Questions tagged [pcre]

Perl Compatible Regular Expressions(PCRE) was initially developed as a regex engine for PERL, but grew into a library that many other languages (like PHP and Apache) use for their regex. Use with the [regex] tag and any appropriate language tags.

PCRE is an initialism for Perl Compatible Regular Expressions. It is both name of a flavor and the library that implements it and makes it available for use by other programs (e.g. , ).

Despite being designed with compatibility in mind, are not 100% compatible with regular expressions (). PCRE passes many of Perl’s regression tests, though. Comparison can be found in community-authored article on Wikipedia, as suggested by PCRE homepage.

Since POSIX regex deprecation in PHP 5.3, PCRE is PHP’s only supported regex engine.

References

2401 questions
1
vote
1 answer

Pcrecpp matches

I use pcrecpp c++ ( PCRE lib ) And i need get all matches in cycle. How can i do it? For example pattern: "hello" and subject: "hello hello hello" Cycle should loop 3 times ( because 3 matches ) 1 hello 2 hello 3 hello Pseudocode pcrecpp::RE…
1
vote
1 answer

PCRE replace multiple values with multiple strings

I am trying to mass replace some keywords in a csv file, for example I have a list of keywords cat,mouse,dog with i would like to replace with something,else,here , I am currently using this http://phpcsv.sourceforge.net/phpcsv-1.0.php it is perfect…
XkiD
  • 159
  • 1
  • 14
1
vote
1 answer

pcre regular expressions: group capture and disjunction - returning a default when no matches occur

I am attempting to search for a string in order to match on several capture groups. In the case of two such capture groups the data is optional, so they may or may not match. I am using pcregrep with option -onumberto return the various capture…
user2051561
  • 838
  • 1
  • 7
  • 21
1
vote
3 answers

Regular Expression Problem: Match in Context

I have a structured file with hierarchical text which describes a GUI in Delphi (a DFM-File). Let's assume I have this file and I have to match all "Color = xxx" Lines, which are in the context of TmyButton (marked), but not those in other context.…
Roman Ganz
  • 1,615
  • 1
  • 20
  • 27
1
vote
1 answer

preg_replace_callback, callback's return value don't replace the matched string

In the following snippet Why doesn't bar replace foo? $subject = "Hello foo"; preg_replace_callback( '/\bfoo\b/i', function ($match) { return 'bar'; }, $subject ); echo $subject;
MTVS
  • 2,046
  • 5
  • 26
  • 37
1
vote
1 answer

Trouble with regex and preg_match() - can't get results to save

I'm building a dynamic linking system for one of the websites that I'm working on, so that you can just put something like {_LINK_20_} and it will dynamically input either the onclick event or href attribute depending on if the user has javascript…
SISYN
  • 2,209
  • 5
  • 24
  • 45
1
vote
0 answers

compiling programs in scientific linux (pcre)

I'm currently trying to install gtk3 on scientific linux (It is not available on official repositories) I'm well used to yum, apt, pacman etc but i'm a little lost here when it's about compiling ... to install gtk3, i need glib, to install glib, i…
Azryel
  • 71
  • 1
  • 11
1
vote
2 answers

PCRE pattern modifier constants, which scope are they visible?

When reading about PCRE Pattern Modifiers I noticed that each modifier has a string literal, which I'm familiar with using, and a constant, which I figured was fair game as an explicit alternative. However, when referring to these constants, say…
Mark Fox
  • 8,694
  • 9
  • 53
  • 75
1
vote
1 answer

preg_replace easy for a pro

i want to find first select ... from and replace that only, following code replace all select..from in sql query, i just need for first select..from preg_replace('#select(.*?)from#is', "select count($expr) as counted from", $sql);
Basit
  • 16,316
  • 31
  • 93
  • 154
1
vote
2 answers

Matching contents inside php tags using regex

I have some trouble matching the contents inside php tags. Currently I have this code, but it's not working for me: /', $str, $inside_php); ?> I need to retrieve the contents so I can do other things with them,…
Smurof
1
vote
0 answers

How to cache precompiled PCRE regexes in a linked list in the fastest way?

Good afternoon, Here is a first cut at a singly linked list C++ class which caches precompiled PCRE regex's. We want to run in the fastest manner. Is it possible to optimize this first cut which compiles and has been briefly tested? Thank you. class…
Frank
  • 1,406
  • 2
  • 16
  • 42
1
vote
2 answers

Irregular RegEx behavior

I have a string: $day = "11.08.2012 PROC BRE-AMS 08:00-12:00 ( MIETWAGEN MIT BAK RES 6049687886 ) Y AMS-AMS 13:15-19:15" And I have a regular expression: $data = preg_split("/(?=[A-Z]{1,4}[\s]+[A-Z]{3}[\-][A-Z]{3}[\s]+)/", $day); The expected…
LostPhysx
  • 3,573
  • 8
  • 43
  • 73
1
vote
1 answer

regex to match subpattern structure

I'm testing out some regex expressions to work with subpatterns so I can aplly through PHP the defined rules for each uri segment. Some of those segments are optional, so I tried this…
yoda
  • 10,834
  • 19
  • 64
  • 92
1
vote
3 answers

Is it an error to escape every metacharacter with PCREs and EREs?

In regular expressions, some characters get the special meaning of metacharacters only if appropriately placed and remain their literal meaning otherwise. For instance, the - character is treated as a metacharacter only if placed within a square…
Desmond Hume
  • 8,037
  • 14
  • 65
  • 112
1
vote
2 answers

PCRE regular expression match the first letter of a string

Could you point me out a PCRE RegEx that would match only the first letter of a string. I need to pass to Mongo DB, I'm concerning about performances at the moment I'm using ^a. Examples: MATCH apple alligator NO MATCH thanks
GibboK
  • 71,848
  • 143
  • 435
  • 658