Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regular expressions - same for all languages?

is the regexp the same between languages?

for example. if i want to use it in javascript, would i have to search for regexp for javascript specifically. cause i got some cheat sheets. it just says regular expression.

i wonder if i could use this on all languages, php, javascript and so on.

like image 661
ajsie Avatar asked Dec 29 '09 07:12

ajsie


2 Answers

The basics are mostly the same but there are some discrepancies between which engine powers the language, PHP and JavaScript differ since PHP uses PCRE (Perl Compatible Regular Expressions).

PHP also has the POSIX-compatible regex engine (ereg_* functions), but that is deprecated.

If you don't already use it, I suggest you try RegexBuddy. It can convert between several Regex engines.

You can find alternatives for RegexBuddy on Mac here.

like image 124
Alix Axel Avatar answered Sep 29 '22 12:09

Alix Axel


You might want to start out by looking here. That's my Bible when I do regexping!

Now, regex should be the same everywhere, at least the fundamentals, however there are cases where it differs from compiler to compiler (or interpreter if you will).

Those could be how you search for a specific pattern, let's take \w as an example, that's: any alphanumeric or underscore character in c# but the pattern in javascript might be different.

When you come to a special case like this, you might want to revise the above provided link.

like image 39
Filip Ekberg Avatar answered Sep 29 '22 10:09

Filip Ekberg