I've got a string, "foo (123) bar", and I want to retrieve all numbers surrounded by the delimiters "(" and ")".
If I use varname.match(/\([0-9]+\)/), my delimiters are included in the ... |
I need to match something in the form
<a href="pic/5" id="piclink"><img src="thumb/5" /></a>
to find the number, in this case 5, using javascript. I have no idea how to use regexes so ... |
I need a javascript regex pattern to match a person's height to check if the input is valid. Here are some sample input:
5' 9"
6'
5'8"
Any ideas?
|
How can I test if a regex matches a string exactly?
var r = /a/;
r.test("a"); // returns true
r.test("ba"); // returns true
testExact(r, "ba"); // should return false
testExact(r, "a"); // should return true
|
Basically, I want to do "zipzam&&&?&&&?&&&" -> "zipzam%26%26%26?&&&?&&&". I can do that without regex many different ways, but it'd cleanup things a tad bit if I could do it with regex.
Thanks
Edit: ... |
I'm trying to match C style comments form a file, but only if the comment don't start with a certain labels introduced by @
For example from
/* some comment to match */
/* ...
|
First of all, pardon my hacky code, I'm just trying to try this out and I'm learning javascript for the first time. Basically, Given the string "abc!random{3}" would mean return a ... |
|
Why does the the RegExp /^\w+$/ match undefined?
Example code:
alert(/^\w+$/.test(undefined));
This will display true in Firefox 3 (only browser I tested it on).
|
Is there any way to match a function block in javascript source code using regular expressions?
(Really I'm trying to find the opposite of that, but I figured this would be a ... |
I'm having a problem writing a regular expression. How could I write the following:
- start with an optional access level (a digit from 1 to 5)
- followed by a space
- then ...
|
In JavaScript/JQuery I want to get all the text that is seen between some other text. For example, if the HTML document had:
<b class="blah">Blah: Some Text 1</b>
<div id="foo"><b class="blah">Blah: Some ...
|
Consider the following Javascript regular expression matching operation:
"class1 MsoClass2\tmsoclass3\t MSOclass4 msoc5".match(/(^|\s)mso.*?(\s|$)/ig);
I would expect it to return [" MsoClass2\t", "\tmsoclass3\t", " MSOclass4 ", " msoc5"]. Instead it returns [" MsoClass2\t", " MSOclass4 ... |
How do I match U1234, but not \U1234 in Javascript?
I can't figure out how to not match the single backslash.
The closest I can get is:
\[\\]{0}U[0-9]{4}\b
But that doesn't work.
Any suggestions?
|
Using JavaScript RegEx.
How can I match a <p> element(including attributes), but not <param> or other HTML elements starting with a "P".
|
I'm confused about the array returned by a regex match when using both /g (to get multiple matches) and parentheses (to get backreferences). It's not clear to me how to get ... |
I have a javascript function that looks element id with certain patterns. So I have the following script:
if (f.elements[i].id.match(/DataList\[-\d{3}|\d{3}\]\.MemberId/)) {
//do something
}
It should match elements with ids such as these:
DataList[-1].MemberId
DataList[-2].MemberId
And ... |
Regex fun again...
Take for example http://something.com/en/page
I want to test for an exact match on /en/ including the forward slashes, otherwise it could match 'en' from other parts of the ... |
I'm banging my head against a wall. I want a regex that matches: empty string, A, AB, and ABC, but not AC. I have this, which works:
/^(A|AB|ABC)?$/
But this is a simplification; ... |
I've got a <textarea> that will be basically a list of names, so I set a function to replace the spaces between the names for a new line.
Now I need to ... |
I'm trying to detect an occurrence of a string within string. But the code below always returns "null". Obviously something went wrong, but since I'm a newbie, I can't spot it. ... |
Is there a way to retrieve the (starting) character positions inside a string of the results of a regex match() in Javascript?
|
string = 'Hello _1234_ world _4567_';
string.match(/(\d*)/gi);
//,,,,,,,1234,,,,,,,,,,4567,,
If I change regext to have \d+ then I get proper values: 1234 and 4567. Why in the first case I am getting all those empty ... |
I have a sentence structure along the lines of
[word1]{word2} is going to the [word3]{word4}
I'm trying to use a javascript regex to match the words for replacement later. To do this, ... |
Hello
i'm trying to find a way to match this problem but i'm LOST
i want it to match a math equation that will accept string if:
- "+-*/%" at anywhere in the string ...
|
I'm using the Jison parser generator for Javascript and am having problems with my language specification.
The program I'm writing will be a calculator that can handle feet, inches ... |
can any one tell me regular expression for postalcode of Amsterdam, Netherlands for validation
EX. 1113 GJ
Postal code format according to Wikipedia (thanks to Pekka):
1011–1199 plus a ... |
I have this string:
sometext +[value]:-
I would like to match the value(1-3 numerical characters) (with regex, javascript)
sometext may contain a +sign if i'm unlucky so I don't wanna end up ... |
How can I write a regex to match strings following these rules?
- 1 letter followed by 4 letters or numbers, then
- 5 letters or numbers, then
- 3 letters or numbers followed by a number ...
|
The following javascript code concatenates the matches found by a regular expression. The regular expression should find any word or set of quoted words. It seems to work perfectly in FireFox ... |
I am currently writing an application in JavaScript where I'm matching input to regular expressions, but I also need to find a way how to match strings to parts of the ... |
given text:1,0397,030 followed by nothing or any number of characters not in the set [,0-9] why is my regex not being greedy enough? Javascript's regex is supposed to be greedy by ... |
What will be the regular expression in javascript to match a name field,
which allows only letters, apostrophes and hyphens?
So that such names as jhon's avat-ar and Josh are valid?
Thanks
|
How do I write a swtich for the following conditional?
If the url contains "foo", then settings.base_url is "bar".
The following is achieving the effect required but I've a feeling this would be ... |
my date formatting in PHP is d-M-Y and I'm trying to match the dates with a javascript regex:
s.match(new RegExp(/^(\d{1,2})(\-)(\w{3})(\-)(\d{4})$/))
To be used with the jQuery plugin, tablesorter. The problem is it's not ... |
I am trying to extract a number from a string. The number might be zero. Numbers appear like this: '+123', '-8' or '0'.
alert( '+123'.match(/[-?|+?]\d+/) );
alerts +123
alert( '-8'.match(/[-?|+?]\d+/) );
alerts -8
alert( '0'.match(/[-?|+?]\d+/) );
alerts ...
|
Given the following text:
This is!!xa simple string!xpattern
I would like to get a regexp that matches the !x that's between "string" and "pattern" but not !!xa that's between "is" and "a".
This regexp ... |
I have an url-encoded url (so with & replaced to &), but I want to replace all the occurences of & back to & using javascript. Currently I'm using myStr.replace("/&/g", "&"), ... |
What is the JavaScript equivalent of this .NET code?
var b = Regex.IsMatch(txt, pattern);
|
I understand that .match() returns an array of the matches, or null if none are found. But how do I go about accessing the values of capturing groups used with .match? ... |
Is it possible in JavaScript to do something like preg_match does in PHP ?
I would like to be able to get two numbers from string:
var text = 'price[5][68]';
into two separated variables:
var ...
|
given:
var regexp = new RegExp("<~~include(.*?)~~>", "g");
What's the easist way in javascript to assign a variable to whatever's matched by .*?
I can do this, but it's a little ugly:
myString.match(regexp).replace("<~~include", "").replace("~~>", "");
|
Been trying to come up with a regex in JS that could split user input like :
"Hi{user,10,default} {foo,10,bar} Hello"
into:
["Hi","{user,10,default} ","{foo,10,bar} ","Hello"]
So far i achieved to split these strings with ({.+?,(?:.+?){2}})|([\w\d\s]+) but ... |
var string = $.trim("How are you ? are you fine ?");
var part = $.trim("How are you ? are you fine ?");
var SearchResult = string.match(part);
if (SearchResult != null && part!="") {
...
|
I have a problem: i should match values from 0.0 to a specific double value (for example, i should match from 0.0 to 150.00 including value as 12, 21.23213, 149.111)
anyone can ... |
var str = "abcd1234";
var first = str.match(/^abcd(\d+)$/)[0]; //matches abcd1234
var number = str.match(/^abcd(\d+)$/)[1]; //matches 1234 only
Why does this regex first match the whole of str and then match the numeric part? Looking ... |
I'm probably doing something very stupid but I can't get following regexp to work in Javascript:
pathCode.replace(new RegExp("\/\/.*$","g"), "");
I want to remove // plus all after the 2 slashes.
|
Given the string:
© 2010 Women’s Flat Track Derby Association (WFTDA)
I want:
2010 -- Women's -- Flat
Women's -- Flat -- Track
Track -- Derby -- Association
I'm using regex:
([a-zA-Z]+)\s([A-Z][a-z]*)\s([a-zA-Z]+)
It's only returning:
s -- Flat ...
|
I need a regular expression can match javascript functions like
function abc(var1, var2){
...
}
...
abc : function(var1, var2){
...
},
...
|
I have this expression to check wether if a key exists in a url :
new RegExp('/'+x+'/ig')
(removed the irrelevant code)
Thing is, it isn't working. I suppose I have to use delimiters (start ... |
I want to write a JavaScript input key validator. I want to use regular expressions for this purpose. When user presses a key - input text field is checked that his ... |
I've got a simple regular expression:
[A-z]{2}[0-9]{3})$/g inside the following:
regForm.submit(function(){
if ($.trim($('#new-usr').val()).match(/([A-z]{2}[0-9]{3})$/g)) {
alert('No');
return false;
}
});
This is correctly reading that something like 'ab123' ... |
How can i change this regular expression
/^[1-9][0-9]{0,3}$|^[1-9][0-9]{0,3}[\.][0-9]$/
to see that it accepts "0.1" and "0.2" and so on values but it should not accept "0.0"
|
Example string: $${a},{s$${d}$$}$$
I'd like to match $${d}$$ first and replace it some text so the string would become $${a},{sd}$$, then $${a},{sd}$$ will be matched.
|
I have several ip addresses like:
115.42.150.37
115.42.150.38
115.42.150.50
What type of regular expression should I write if I want to search for the all the 3 ip addresses? Eg, if I do 115.42.150.* (I ... |
Why would you use \(?:\d+)alp*ha\ rather than \\d+alp*ha\ ??
|
I have a string, which I want to extract the value out. The string is something like this:
cdata = "![CDATA[cu1hcmod6rbg3eenmk9p80c484ma9B]]";
And I ... |
I am developing a web application for a school. They have terms like course_name and class_name. Think of a course as a template for a class, meaning that a ... |
I have a string and I need to find out what was matched in the string. For example:
var txt = "Hello world!";
txt.replace(/[a-h]/gi, '<span>' + TEXT_MATCHED + '</span');
I would like the output ... |
I want to wrap all occurrences of certain words in a given string with square brackets in JavaScript.
Say these words are apples, oranges, and bananas. Then a subject text "You are ... |
I need to split a string like the one below, based on space as the delimiter. But any space within a quote should be preserved. There are two cases which needs ... |
Let's say I have a block of text and I want to replace each instance of the word "the" with an indexed number.
For example...
"The great white shark is the father of ... |
console.log(r.message); //returns "This transaction has been authorized"
if (r.message.match(/approved/).length > 0 || r.message.match(/authorized/).length > 0) {
// ^ throws the error: r.message.match(/approved/) is null
Is this not the correct way to do matching in ... |
I'm trying to match the last name of a value of an ini line.
foo.bar.far.boo = "some value"
I can match 'boo =' but I just need 'boo'
I do (\w+)\s*= but it matches ... |
In a previous question, I asked how to match a part of the property of an ini value.
I got answered and it works great with a positive lookahead.
Now, I'm trying ... |
The text is:
Here is some text!
The regular expression (looking for a single match) is:
Here is (\w+\s?)+
In .NET there is one match: Here is some text
...but in javascript there are two: Here ... |
I am trying to implement the following regex search found on golfscript syntax page.
var ptrn = /[a-zA-Z_][a-zA-Z0-9_]*|'(?:\\.|[^'])*'?|"(?:\\.|[^"])*"?|-?[0-9]+|#[^\n\r]*|./mg;
input = ptrn.exec(input);
Input is only ever the first match of the regexp. for ... |
I have a question that I can't resolve. I have strings that contains hashtags, for example '#question' or '#idea'.
The question is how extract the hashtag?
var hashtag = str.match(/#question?#idea?/i);
Is this regexp correct?
... |
When I use switch statement , none of the cases matches the 'prefix'.
But if I replace switch statement with if-else, everything works.
Why?
Thank you
//UPDATED
//el is DIV element. For example el.id='mph_4';
var prefix ...
|
I have a string that may contain 0 or more urls. I want to replace each url in the string with that url wrapped in <a></a>. Is there a way I ... |
Hi I am trying to get the following javascript code to work. When I am typing a line containing all three names
fever, nightsweats and nocturia - I want an alert window ... |
How can I find everything between the hyphens with regex?
Array answer for below should be ["aaa","bbb","ccc","ddd"]
<script>
myRe= new RegExp ("xxxxxx");
myArray = myRe.exec("-aaa-bbb-ccc-ddd-");
</script>
Also... what happens if there are comma's in the ... |
I need to check using regex that a string matches this format:
http://site.com/users/1
e.g. a matching string is http://stackoverflow.com/users/587532 and http://stackoverflow.com/users/587532/umar should be not matching.
but I don't know the regex code to do ... |
I have a RegExp:
/.?(NCAA|Division|I|Basketball|Champions,|1939-2011).?/gi
and some text "Champion"
somehow, this is coming back as a match, am I crazy?
0: "pio"
1: "i"
index: 4
input: "Champion"
length: 2
the loop is here:
// contruct the pattern, dynamically
var someText = ...
|
I want to write a regex that matches the "()" one time in:
hello()
hello(asd, 2)
hello(asd,sad))
That is, the 1st and the 2nd one should match but not the 3rd one.
Also the () has ... |
I am writing a bit of javascript that grabs user ID's. It works, but the problem is the actual regular expression is being included in the results.
My code it:
var regex = ...
|
I am trying to find for the string of the format abc1234. I can compare character taking at each index whether is alpha or numeric and get the result. Instead wrote ... |
What will be the regular expression to match {0} in a piece of text?
so that if I have
var temp = 'this is my {0} attempt';
I could use that regular ... |
I need som regex help. I have this code that i want to match.
var i1 = "<ul> {{#items}}<li>{{.}}</li>{{/items}} </ul>";
var i2 = "<ul> {{#items}}<li>{{.}}</li> <li><ul> {{#items}}<li>{{.}}</li>{{/items}} </ul></li>{{/items}} </ul>";
var i3 = "<ul> ...
|
what's wrong with match() in javascript ?
var path = "D:\Programs\DeveloperTools";
var patt=/.+\\/g;
alert(path.match(patt));
The Result Should Be :
D:\Programs\
|
I need a regex to match INT or INT, or INT , to split a String, the String could also contain similar words like INTEGER, INT444, INTEGER2, etc. but they ... |
I encountered a strange question when i used the match method of the String. Using the following code
var str2 = " aa bb cc",
greg = /((\S)\2)/g;
greg.lastIndex = ...
|
I would like help on building a regular expression to find ACII codes
So far I came up with this, http://jsfiddle.net/G7cab/
but as you'll notice I'm not capturing all the groups ... |
What is the regex (in javascript if it matters) to only match if the text is an exact match, ie no extra characters at each end. For example.
Trying to match ... |
I am new to regular expressions. I'm trying to parse the following kind of string:
[key:"val" key2:"val2"]
where there are arbitrary key:"val" pairs inside. I want to grab the key name and the ... |
I'm struggling to create a regex expresion in Javascript to match values between 5pt and 30pt.
That is 5pt, 6pt, 7pt, ..., 29pt and 30pt. The value should have a number between ... |
I've made a JavaScript regular expression to change instances of vertical-bar-sets for a LaTeX renderer, but when I have multiple such instances within the same paragraph it affects only the very ... |
I am just starting to learn js and I got stuck to regexp at a specific expression. Can you figure out what !![a-z]* will match ?
I can't seem to figure ... |
I'm trying to write a regexp which allow me to filter out all the url addresses having this shape.
http://foo.com/
http://foo
http://foo.*
But not the following:
http://foo.com/subfoo
http://foo.com/subfoo/
http://foo.com/subfoo/subsubfoo..
In order to match the second url group i've written ... |
I am having an issue with my javascript match() regex.
<div class="a"> whitespace, new lines, and content </div>
<div class="junk"> ...
|
I have small requirement.I want to search a string with exact match.
Suppose i want to search for None_1, i am searching for 'None_1' using /None_1/, but it is matching even "xxxNone" ... |
I'm trying to match the email regex \b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b with a string in Javascript. At the moment I'm using the code email.match(/b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/) but it doesn't match any email addresses. Do regex's need ... |
I have the following regular expression in JavaScript which matches strings like "12:23:34:45" and "12:23"
/^([0-9]{1,2}\:){0,3}([0-9]{0,2})?$/
The problem I have is that when I look at the match data there are only ever ... |
I have this kind of expression:
var string = [a][1] [b][2] [c][3] [d .-][] [e][4]
I woud like to match the fourth element [d .-][] which may contain any character (letters, numbers, ... |
I want to use JavaScript (or jQuery) to do some client-side validation to check whether a string matches the regex:
^([a-z0-9]{5,})$
Ideally it would be an expression that returned true or false.
I'm ... |
I just can't get this thing to work in javascript. So, I have a text "game_1" without the quotes and now i want to get that number out of it and ... |
I have the following regex in javascript. I want to match a string so its product (,|x) quantity, each price. The following regex does this; however it returns an array with ... |
How to write a regex for string matches which starts with @ or end with ,. I am looking for a code in JavaScript.
|
I know first off that this is probably the worst looking regex ever but here goes.
I have this regex
(?:http://)?(?:www.)?youtu(?:be)?.(?:[a-z]){2,3}(?:[a-z/?=]+)([a-zA-Z0-9-_]{11})(?:[a-z0-9?&-_=]+)?
which is capable of matching any of these
www.youtu.be/watch?v=QH2-TGUlwu4
http://www.youtube.com/watch?v=QH2-TGUlwu4&feature=related
http://youtu.be/QH2-TGUlwu4
http://www.youtube.com/embed/QH2-TGUlwu4
http://www.youtube.com/v/QH2-TGUlwu4?version=3&hl=en_US
What it does in javascript is ... |
Yesterday 'Hnatt' was kind enough to offer the regex portion of this script :
<html>
<body>
<script type="text/javascript">
alert("hhhhhh yadad ...
|
I can't see where I went wrong here:
var TestString = '+test +"testing multi" -not -"and not this" "w00t" hehe nice +\'test this\' -\'and this as well\'';
var regex = new RegExp('([\\+\\-]{0,1}([\\\'"]).*?\\1|[^\\s]+)', 'g');
var ...
|