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

Correcting an illegal PCRE regex in PHP

Update 5/26 I've fixed the behavior of the regular expressions that were previously contained in this question, but as others have mentioned, my syntax still wasn't correct. Apparently the fact that it compiles is due to PHP's preg_* family of…
SISYN
  • 2,209
  • 5
  • 24
  • 45
1
vote
1 answer

How to use StringRegExp with multi-line text?

I was trying to use StringRegExp() to match multi-line text, but no success so far. $sHTML = "Keyword[wellwellwell bla bla bla bla bla bla bla

bla bla

=NeedRegExp-123123123asd endline Keyword[wellwellwell" $array =…
mirza
  • 5,685
  • 10
  • 43
  • 73
1
vote
2 answers

Regex - And and Not match

Trying to get this regex working. [a-z0-9-\.]+(?!.in-addr.arpa*$) sample - sdfgsed.co.in //shall match 1.1.1.1.in-addr.arpa //shall not match fgsagf.co.ru //shall match agfasfdg21.cn //shall match EDIT -…
Majoris
  • 2,963
  • 6
  • 47
  • 81
1
vote
2 answers

ignoring case in libpcre with c

How do I ignore case when using pcre_compile and pcre_exec? pcre_exec( pcre_compile(pattern,0,&error,&erroroffset,0), 0, string, strlen(string), 0, 0, ovector, sizeof(ovector)); what option do i use and where do i specify it?
user105033
  • 18,800
  • 19
  • 58
  • 69
1
vote
3 answers

PCRE regex multi-line match help needed

I am having trouble matching the pattern, "This program cannot be run" whenever the phrase is broken over multiple lines, e.g.: This program cannot be run T his program cannot be run Thi s program cannot be run . . This pr ogram cannot be…
user2249813
  • 25
  • 1
  • 4
1
vote
2 answers

PHP preg_replace surrounded by pipes?

I have just come across a regular expression in the WordPress core which intrigues me... I have found regular expressions like this before and wondered about them, but they have worked so I have not altered them. The pieces of which I am interested…
Shane
  • 2,007
  • 18
  • 33
1
vote
1 answer

PCRE Regex help needed

I am having trouble writing a perl compatible regex to match a few different things when there is a gap between each condition. It makes more sense when I explain what I want it to find Conditions /world/ a single letter a dash OR underscore a…
user2249813
  • 25
  • 1
  • 4
1
vote
4 answers

regexp match within a log file, return dynamic content above and below match

I have some catchall log files in a format as follows: timestamp event summary foo details account name: userA bar more details timestamp event summary baz details account name: userB qux more details timestamp etc. I would like to search the log…
rojo
  • 24,000
  • 5
  • 55
  • 101
1
vote
1 answer

How can I extract RFC1123 hostnames from a string using regular expressions?

I'm looking for a regular expression that would match anything that could be a valid RFC1123 hostname in a string that can contain anything. The idea is to extract everything that could possibly be a hostname (by checking that the substring follows…
Protected
  • 362
  • 1
  • 7
  • 16
1
vote
4 answers

RegEx to match some wrapped texts

Consider following text: aas( I)f df (as)(dfdsf)(adf).dgdf(sfg).(dfdf) asdfsdf dsfa(asd #54 54 !fa.) sdf I want to retrive text between parenthesis, but adjacent parentheses should be consider a single unit. How can I do that? For above example…
Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
1
vote
2 answers

regex - get all attributes of an element

I have a string that contains some html entities Text description any can be written  where…
1
vote
1 answer

PHP PCRE - match different subpattern name depending on context

As the title states, I started thinking about how to match, for example, 2 different subpatterns in a regex applied on a string, on the condition that if the content has only numbers it will be assigned the subpattern name , otherwise (letters…
yoda
  • 10,834
  • 19
  • 64
  • 92
1
vote
1 answer

Regex negative character class and dot-asterisk

I need to get the following regular expression to work but having issues. Yes, it's parsing HTML. No, there's no better option to use. This is the regex: test(.*)\/[^s].*(=|\/|Z) I'm using the "U" modifier (so it's ungreedy), and "\" is my escape…
FoulFoot
  • 655
  • 5
  • 9
1
vote
1 answer

php - regex - how to parse the text within two different tags

I have an HTML string like below: $string = "\n

heading 2

\n\nwhatever we are doing is good to have one thing\n

heading 3

\nnext paragraph goes there\n

new heading 2

\n\npara succeeded for new heading 2\n\n

heading…