Tag: regex

Find text by search and highlight current result only

Trying to highlight current/single text only, like browser “Control-F” keyboard command search. find next/new text when search again is good. But it’s highlight all result, trying to highlight only Current result/text. JS below: $(‘body’).on(‘keydown’, ‘#searchfor’, function(e) { if (e.which === 32 && e.target.selectionStart === 0) { return false; } }); //Create some vars to later […]

RegEx to extract parenthesis and function name

Somebody help me to write RegEx for the following cases somestring() => [‘somestring’] somestring()[10] => [‘somestring’,”,10] somestring(‘argString’) => [‘somestring’, ‘argString’] somestring(‘argString’)[10] =>[‘somestring’, ‘argString’,10] somestring({prop1:’v1′,prop2:’v2′}) => [‘somestring’, {prop1:’v1′,prop2:’v2′}] somestring({prop1:’v1′,prop2:’v2′})[100] => [‘somestring’, {prop1:’v1′,prop2:’v2′},100] This is I tried so far var regExp = /\b[^()]+\((.*)\)+\[(.*?)]/; var matches = regExp.exec(‘somestring()[10]’);

Sentence case a passage of text while ignoring html elements within

At the moment I am passing a passage of text to the following function, in order to make sure that the first letter of each sentence is capitalised. function sentenceCase(string) { var n = string.split(“.”); var vfinal = “” for (i = 0; i < n.length; i++) { var spaceput = “” var spaceCount = […]

Weird Javascript Regex Replace Backreference Behavior

why does the following js expression: “test1 foo bar test2”.replace(/foo.bar/, “$'”) result in the following string? “test1 test2 test2” is the $’ in the replace string some sort of control code for including everything after the match??? this behavior was screwing with me most of the day. can anyone explain this? thanks a lot ps- […]

Is the JavaScript RegExp implicit method deprecated?

So everyone knows what I mean by “implicit methods”? They’re like those default properties from the Windows COM days of yore, where you could type something like val = obj(arguments) and it would be interpreted as val = obj.defaultMethod(arguments) I just found out JavaScript has the same thing: the default method of a RegExp object […]

How to write regex to validate dates?

I’m working in JavaScript and I need to figure out how to determine a valid date using regular expressions. The matches will be: dd-mm-yyyy dd-mm-yy Also, no leading zeros should be accepted like: 9-8-2010 10-6-99 How can I write a regular expression to do this?

Javascript Regex Browser Inconsistancy?

I have a regex that I am using in an asp.net RegularExpressionValidator to check a TextField. ^(?=.*[a-z])(?=.*\d)(?=.*[A-Z]).{8,}$ The example string I have stumbled on is ‘RedCoal1’ Firefox = Matched IE8 = Matched Chrome = Matched IE7 = DOES NOT MATCH WHY!!!!

How to replace text not within a specific-Tag in JavaScript

I have a string (partly HTML) where I want to replace the string 🙂 into bbcode :wink:. But this replacement should not happen within <pre>, but in any other tag (or even not within a tag). For example, I want to replace :-)<pre>:-)</pre><blockquote>:-)</blockquote> to: :wink:<pre>:-)</pre><blockquote>:wink:</blockquote> I already tried it with the following RegEx, but it […]

How to allow only “numbers”,“-” and “()” using JavaScript

I have to do phone number validation using JavaScript. I have already done validation for numbers as follows, var filter =/^[0-9]+$/ But now I have to also allow hyphen and “()”. Please provide me a way for the same.

Regex Javascript 0-9a-zA-Z plus whitespace, commas etc

Can anyone help me with this regex? I need something which will ALLOW: 0-9 a-z A-Z spaces hyphens apostrophes But disallow all other special characters. I’ve got this, but it’s not working: “regex”:”/^[0-9a-zA-Z/ /-‘_]+$/”, Thanks for any help!