Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript regular expressions as functions?

Apparently, back in Firefox 3.6, the following was legitimate:

/[0-9]{3}/('23 2 34 678 9 09')

and the result was '678'.

FF8 isn't having any. What's the right syntax now?

like image 264
bmargulies Avatar asked Dec 17 '11 20:12

bmargulies


People also ask

Can I use RegEx in JavaScript?

In JavaScript, you can use regular expressions with RegExp() methods: test() and exec() . There are also some string methods that allow you to pass RegEx as its parameter. They are: match() , replace() , search() , and split() . Executes a search for a match in a string and returns an array of information.

How does JS RegEx work?

Regular expressions are a sequence of characters that are used for matching character combinations in strings for text matching/searching. In JavaScript, regular expressions are search patterns (JavaScript objects) from sequences of characters. RegExp makes searching and matching of strings easier and faster.

Is Subb () is a RegEx function?

sub() function belongs to the Regular Expressions ( re ) module in Python. It returns a string where all matching occurrences of the specified pattern are replaced by the replace string. To use this function, we need to import the re module first.


1 Answers

Do you want

/[0-9]{3}/.test('23 2 34 678 9 09');

or

/[0-9]{3}/.exec('23 2 34 678 9 09');
like image 58
Adam Rackis Avatar answered Sep 16 '22 20:09

Adam Rackis