-1

I need to backtrace a string for a particular value to parse out. Is there any way to get the required output by using regular expressions.

;2N9XsPQQ;PARAMETER_STRING=

Required o/p : 2N9XsPQQ

Thanks in Advance

Dileep
  • 624
  • 3
  • 10
  • 20
  • It's unclear to me what you mean by "backtrace" or "parse out a string in reverse." From your sample all I can infer is that you want the value delimited by semicolons. Can you clarify? – ScottMcG Nov 18 '15 at 01:32
  • 1
    @Dileep: if the solution proposed works for you please accept it or explain why it doesn't, i'll try to fix accordingly. – Giuseppe Ricupero Nov 18 '15 at 16:53

2 Answers2

0

Try this

\;([0-9a-zA-Z]+)\;.*?\=

https://regex101.com/r/vC6nZ7/1

nguaman
  • 925
  • 1
  • 9
  • 23
0

I think a simple:

NSString *pattern = @"(?<=;).*(?=;)"; //or equivalent

will do the work for you.

Online demo

UPDATE

On Netezza SQL the lookbehind is not available so try one of the alternative solutions:

# Tested on Postgresql (no Netezza, postgres derived db, available atm)
SELECT regexp_matches('123abc;2N9XsPQQ;PARAMETER_STRING=',';(.*);');
# OR
SELECT regexp_replace('123abc;2N9XsPQQ;PARAMETER_STRING=','.*;(.*);.*','\1');
Giuseppe Ricupero
  • 6,134
  • 3
  • 23
  • 32
  • i'm trying to parse out the string by using Netezza SQL. it is giving null for me. dldhhahddsahhgdgsagdjsdg5dcdsa5;2N9XsPQQ;PARAMETER_STRING=dsagD%SDBHSDBAHS^ this is like my string. – Dileep Nov 16 '15 at 12:44
  • @Dileep: i cannot test against Netezza SQL, i've tested on Postgres (from which Netezza is derived). I'm pretty sure both methods are correct. Let me know – Giuseppe Ricupero Nov 16 '15 at 13:26