简体   繁体   中英

Replace query string with regular expression?

I have a query string parameter looks like below:

Nr=AND(OR(abc:def),OR(ghi:jkl),OR(mno:pqr).....so on)

I wanted to replace this query string to get the values inside the OR condition delimited between colon.

any help will be appreciated.!!

The below regex would capture the text inside OR function and stored it into two separate groups using : as delimiter,

OR\(([^:]*):([^)]*)\)

DEMO

Explanation:

  • OR\\( Matches literal OR( .

  • ([^:]*) NOt of : character zero or more times. Finally it stores the matched characters into group1.

  • : A literal :

  • ([^)]*) Not of a literal ) character zero or more times. Finally it stores the matched characters into group2.

  • \\) Matches a literal ) character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM