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

Regular expression to perform named capture of user agent string variations

I am trying to come up with a regular expression capable of capturing an entire user agent string as a single named group logged in one of the 2 following formats: Mozilla/5.0+(compatible;+MSIE+9.0;+Windows+NT+6.1;+WOW64;+Trident/5.0) "Mozilla/5.0…
porcus
  • 823
  • 8
  • 11
1
vote
2 answers

Extracting tail from a string using PCRE

I am looking for a PCRE regular expression match pattern with which I can use in C language to extract the tail fragment of a string. My expected effect is to extract the string following string "en", which can be immediately followed by nothing,…
Masao Liu
  • 749
  • 2
  • 7
  • 16
1
vote
1 answer

Find URLs in HTML-Sourcecode which are not yet tagged. Ignore tagged URLs

I'd like to find URLs in HTML Sourcecode. But only URL which don't have Tags around them. I came up with this: (?) It does a good job avoiding URL which are part of links but…
shorshe
  • 13
  • 4
1
vote
1 answer

pcre regex for removing adjacent duplicates

Given a string having duplicate characters, what would be the proper regex to remove adjacent duplicates? I am unable to figure out how to use backreference to write final output. For eg. input: "1111112222223333344444111"; output: "12341"
Sushil
  • 390
  • 2
  • 15
1
vote
5 answers

Regular expression libraries for Mac OS X 10.6

Is there a library compatible with PCRE that can be used on Mac OS X 10.6, and which is Unicode compatible? I was thinking to use the predicates, but it is a little excessive when the application is not already using Spotlight predicates.
apaderno
  • 28,547
  • 16
  • 75
  • 90
1
vote
2 answers

Match a code string in some text

I have some code strings that I need to extract some data from, but specific data at that. The strings are always in the same format. I need to extract the text at the beginning between the ( and ), so it would extract List Options here. I need to…
user2806964
1
vote
3 answers
1
vote
2 answers

grep equivalent to pcre's `?` operator

With PCRE you'd do ax?a to find strings like aa and axa. How would you write a regex for grep that'd do that?
neubert
  • 15,947
  • 24
  • 120
  • 212
1
vote
1 answer

Haskell regex-pcre negate expression

How can I achieve an inverse match so that for example getAllTextMatches $ "foobar bar bl a" =~ pattern :: [String] would prodcuce a list of strings that are not multiple whitespace. I've tried getAllTextMatches $ "foobar bar bl a"…
1
vote
1 answer

Testing if a user input string contains a regular expression

In my program I allow an administrator to define what a particular string format should be in part of a template document. This may contain a regular expression, or it might just be a literal string. If it's a literal string, then I want to copy the…
Piers
  • 723
  • 1
  • 6
  • 18
1
vote
1 answer

pcre can not support mutiple subgroups

This is about pcre multiple subgroups, subject is : const char* subject = "http://mail.google.com:443"; I wanna to find protocol&domain&port, and my regex like this, but pcre_exec return 0 const char* regex_str = "([^/]+)//([^:]+):(\\d+)"; but…
gaconel
  • 11
  • 2
1
vote
1 answer

Can a string be padded to match a regular expression?

I'm facing an optimization problem in a program that searches files whose path match a given regular expression (PCRE). Typical expressions could be: ^C:\test\(a|b)\foo\bar ^C:\test\[^\\]+\foo ^C:\test\.*\foo Right now the implementation detects…
Daniel Stelter
  • 466
  • 3
  • 6
1
vote
0 answers

Rebuild PHP with the newest PCRE

I have a Ubuntu 12.04 server where I updated the PHP from 5.3 to 5.4 but the PCRE version is still at 8.12. I then installed pcre from source and it should be the 8.33 version but php info is still showing 8.12. How can I make PHP use the new…
ObSeSSeN
  • 130
  • 6
1
vote
1 answer

PCRE whole word match (only spaces allowed as separator)

I want to match string as a whole word match "~\b$search\b~i", it matches '35' to '35-40'. I want only space to be separator between words. Test cases: Matching 35 in following cases: 35-40 => false 3-5 => false 335 => false 350 => false 35 =>…
Osvaldas
  • 13
  • 2
1
vote
1 answer

PHP 5.4 - CodeIgniter - PCRE library issue workaround in shared-hosting

I'm going to move codeigniter project from my computer to a public server (virtual private server where it has Cpanel installed in it). In the public server I got the error : Message: preg_match(): Compilation failed: unknown option bit(s) set at…
Hendry H.
  • 1,482
  • 3
  • 13
  • 27