How do I convert this PHP regex to Javascript?

Asked
Active3 hr before
Viewed126 times

7 Answers

regexconvert
90%

You can find more information about regular expressions in JavaScript in this manual from MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions., Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,Thanks for contributing an answer to Stack Overflow!,Nothing really special. PHP regex syntax is very much the same as in JavaScript:

Nothing really special. PHP regex syntax is very much the same as in JavaScript:

str = str.replace(/\(\d*\)|\/\(P\)\//g, "");
88%

I'd love to match this with a client-side regular expression in JavaScript. Can anyone tell me how to convert the following PHP regex to JavaScript?,I have a PHP regular expression I'm using to get the YouTube video code out of a URL.,Nothing really special. PHP regex syntax is very much the same as in JavaScript:,Read http://stackoverflow.com/questions/280712/javascript-unicode to learn more information about unicode in regex with JavaScript.

I'd love to match this with a client-side regular expression in JavaScript. Can anyone tell me how to convert the following PHP regex to JavaScript?

preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v/)[^&n]+(?=?)|(?<=embed/)[^&n]+|(?<=v=)[^&n]+|(?<=youtu.be/)[^&??n]+#", $url, $matches);
load more v
72%

Nothing really special. PHP regex syntax is very much the same as in JavaScript:,I am having an issue with this regex. from PHP,You can find more information about regular expressions in JavaScript in this manual from MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions.

I am having an issue with this regex. from PHP

/(d*)|/(P) //

used like this

preg_replace('/(d*)|/(P)//', '', $string);

how can I convert this to work on JS ?

str.replace();
load more v
65%

I'd love to match this with a client-side regular expression in JavaScript. Can anyone tell me how to convert the following PHP regex to JavaScript?,I have a PHP regular expression I'm using to get the YouTube video code out of a URL.,I think the only problem is to get rid of the lookbehind assertions (?<=...), they are not supported in Javascript.,Javascript: negative lookbehind equivalent?

I'd love to match this with a client-side regular expression in JavaScript. Can anyone tell me how to convert the following PHP regex to JavaScript?

preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v/)[^&] + ( ? = ? ) | ( ? <= embed / )[ ^ & ] + | ( ? <= v = )[ ^ & ] + | ( ? <= youtu.be / )[ ^ & ‌​n] + # ", $url, $matches);
load more v
75%

I've been struggling all day to try and convert the following regex that works for php, into a form for javascript. I am trying to use it for some VBA where I can replace "sedol" with a variable so I can loop through the string to get "name" and other elements So for example below I would want the outcome to = '0452173',If you add any files,it will delete all existing files related to this answer-(only this answer),If you add any files,it will delete all existing files related to this question-(questions only answer remains unchanged),Note** this option does not delete the question immediately,Since others contribution also matters and security reasons.Your request will be Queued.We will review the question and remove.It may take some days.

php regex:

( ? <= "sedol" : ")(.+?)(?=", ")

String extract:

"sedol": "0452173", "name": "Aberdeen Japan Equity (Class I)", .....
load more v
40%

There are some differences between regex engines in Javascript and PHP. Please check Comparison of regular-expression engines article for theoretical and Difference between PHP regex and JavaScript regex answer for practical information.,Most of the time, you can use Javascript regex patterns in PHP with small modifications. As a fundamental difference, PHP regex is defined as a string (or in a string) like this:,Javascript regex is not, it's defined in its own way:,You can give it a try by running the regex on PHP. As a recommendation, do not replace it in Codeigniter files, you can simply extend or replace native library. You can check Creating Libraries out for more information.

Most of the time, you can use Javascript regex patterns in PHP with small modifications. As a fundamental difference, PHP regex is defined as a string (or in a string) like this:

preg_match('/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/', $telephone);
load more v
22%

The preg_replace() function will replace all of the matches of the pattern in a string with another string.,Note: If your expression needs to search for one of the special characters you can use a backslash ( \ ) to escape them. For example, to search for one or more question marks you can use the following expression: $pattern = '/\?+/';,The preg_match_all() function will tell you how many matches were found for a pattern in a string.,The reference contains descriptions and examples of all Regular Expression functions.

In the example above, / is the delimiter, w3schools is the pattern that is being searched for, and i is a modifier that makes the search case-insensitive.

/

In the example above, / is the delimiter, w3schools is the pattern that is being searched for, and i is a modifier that makes the search case-insensitive.

i
load more v

Other "regex-convert" queries related to "How do I convert this PHP regex to Javascript?"