0

I have some queries like:

"$Prefex" SELECT column_name(s) FROM table_name WHERE pal pal pal LIMIT "$Suffix"

These queries have unwanted prefixes and suffixes. I used a regex to get rid of the prefix using a non-greedy .*?SELECT.

I couldn't find a way to use the non-greedy modifier searching backward to eliminate the suffixes.

Ideally, I want a pattern to eliminate from the end of the line to the first match of "LIMIT". If I use LIMIT.*? it wan't match anything, while if I use just LIMIT.* it was greedy, which I want to avoid.

I'm using Ruby for my language.

This is example of the query:

SELECT DISTINCT $val1 $val2 WHERE {  $val1 a foaf:val1.$val1 foaf:val2 $val2. FILTER regex($val2 , "CITY LIMITED" , "i")} LIMIT 20&output=xml HTTP/1.1" 200 604 "-" "Python-urllib/2.6" "GB" "65465666654626426246524"

And this is the desired output:

SELECT DISTINCT $val1 $val2 WHERE {  $val1 a foaf:val1.$val1 foaf:val2 $val2. FILTER regex($val2 , "CITY LIMITED" , "i")}
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
EurikaIam
  • 136
  • 9

2 Answers2

0

Assuming your input is like:

"$Prefex" SELECT column_name(s) FROM table_name WHERE pal pal pal LIMIT "$Suffix"

Then this regex will return your query with any text following the LIMIT, up to and not including the first ":

/(SELECT.*?LIMIT.*?\}).*?/
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
fullybaked
  • 4,117
  • 1
  • 24
  • 37
0

Ideally, I want a pattern to eliminate from the end of the line to the first match of "LIMIT".

Search for

/LIMIT((?!LIMIT).)*$/

and replace with nothing.

Armali
  • 18,255
  • 14
  • 57
  • 171