Questions tagged [recursive-regex]

Using a regular expression to parse an expression which contains the same expression e.g. `{ foo bar {zoo} }`

A recursive expression is an expression which contains the same expression, e.g. { foo bar {zoo} } contains an expression {...} which contains an expression {...}. Such expressions are typically expressed using a Context-free language.

However, a regular expression is only capable to parse an expression which uses a Regular Grammar.

Thus, this tag suggests that a user wants to parse a recursive expression using a regular expression, which is not possible. Typically, the user knows regular expressions, but is not really aware of the limitations, so it asks the SO community.

There is no unique solution to that problem since it depends on the grammar of the expression to parse (e.g. the user may want to limit the recursion levels).

Recursive expressions should not be confused with repeated expressions (e.g. {foo} {bar} {zoo}) which can be parsed using regular expressions.

48 questions
1
vote
2 answers

Java regex library with recursion support

I am looking for a Java regexp lib with support for recursion, like: "" JDK does not support it, ORO does neither. Anyone knows about such? Thanks, Ondra Edit: See http://www.php.net/manual/en/regexp.reference.recursive.php And I need it…
Ondra Žižka
  • 36,997
  • 35
  • 184
  • 250
1
vote
1 answer

search array for duplicates php

It's been years since I've used PHP and I am more than a little rusty. I am trying to write a quick script that will open a large file and split it into an array and then look for similar occurrences in each value. For example, the file consist of…
1
vote
1 answer

About php regexp for recursive pattern

I've this code: $string="some text {@block}outside{@block}inside{@}outside{@} other text"; function catchPattern($string,$layer){ preg_match_all( "/\{@block\}". "(". "(". "[^()]*|(?R)". ")*". ")". …
sensorario
  • 15,862
  • 24
  • 85
  • 131
0
votes
4 answers

Java regex: How to replace all character inside a bracket?

How do I able to replace: ((90+1)%(100-4)) + ((90+1)%(100-4/(6-4))) - (var1%(var2%var3(var4-var5))) with XYZ((90+1),(100-4)) + XYZ((90+1),100-4/(6-4)) - XYZ(var1,XYZ(var2,var3(var4-var5))) with regex? Thanks, J
CK Ho
  • 53
  • 4
0
votes
3 answers

Better Way to write this to escape HTML content

I have string which rich text content something like this for example

Hello


Christian

 Don't Know what to do 
Now I want dont want script to be present in the above content and if present esape it so If I have…
Viren
  • 5,764
  • 6
  • 35
  • 91
0
votes
1 answer

How to find many instances of a specific pattern in RegEx?

Currently (in PHP) I have the following regex pattern: \[(.*) (.*)=(.*)\] This matches [doSomething limitation=true] The end result being that my code will interpret that string and replace it with whatever value is coded to return for it. However,…
user85569
  • 394
  • 3
  • 10
0
votes
0 answers

how to extract who text between set of matching brackets

Possible Duplicate: Regular Expression to match outer brackets Can I use Perl regular expressions to match balanced text? i would like to extract a whole text which has matching numbers of closing brackets. Here is the example text. Big String 1…
mkt2012
  • 241
  • 1
  • 3
  • 8
0
votes
1 answer

`preg_match_all()` yields incorrect/null results

The question Why do I get the wrong results? How can I get the desired results? The input file vulture (wing) tabulations: one leg; two legs; flying father; master; patriarch mat (box) pedistal; blockade; pilar animal belly (oval) old style:…
Wolfpack'08
  • 3,412
  • 8
  • 41
  • 72
0
votes
2 answers

Recursive regex with garbled text surrounding? Getting "ArrayArray"

I asked a similar question, but it was closed for being too broad. Basically, I have a bunch of questions like this. I'm hoping just asking one will be easier. I've tried some different ways to solve this, but none of them actually work. I have a…
Wolfpack'08
  • 3,412
  • 8
  • 41
  • 72
0
votes
0 answers

How to use recursive PCRE regex to match nested css?

I am trying to use recursive PCRE php regex to recover individual results from nested css codes (strings):
celsowm
  • 749
  • 7
  • 28
  • 48
0
votes
1 answer

Does Classic ASP have an object that I can use to browse and modify DOM elements on the server?

I am working in a classic asp application that requires functionality that will modify code that the user copy and pastes into a form. The user is considered a trusted user who is not familiar with html. I am trying to make it so that if the user…
quakkels
  • 11,058
  • 24
  • 87
  • 147
0
votes
1 answer

Renamespacing c++ header with perl - multiline issues

I am trying to enclose the namespace of a c++ header-only library in a custom namespace to avoid symbol name collisions with customer code. Here is the perl script i wrote. It should enclose the def namespace in the abc…
Richard
  • 959
  • 8
  • 23
0
votes
2 answers

Regex for nested XML attributes

Lets say I have following string: "sop} z={ ABC }> }>" How can I write general purpose regex (tag names change, attribute names change) to match content inside {}, either
sop
or
ma2s
  • 1,202
  • 1
  • 8
  • 20
0
votes
1 answer

How to catch any file recursively

The following code catches all files recursively in the php extension. $paths = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($realPath), \RecursiveIteratorIterator::SELF_FIRST); $files = new \RegexIterator($paths, '/\.(?:php)$/',…
Slowaways
  • 257
  • 1
  • 4
  • 16
0
votes
4 answers

Getting the outer most delimiters in Regular Expressions

Is there a way using regular expressions to get the text in between outermost delimiters? I have a string here and want to get the text in between the outermost {%%% and %%%} delimiters: Hello…
Chris
  • 239
  • 2
  • 11