can you please help me understand this regexp

Dear experts,

I got the code of the Web site only.

But I am not able to understand.

I know its very basic question and I need to us in the form of documentation.

Please help understand this code



with data_cell as (
                   select  q'~[{"id":"1666","issueId":"ezsats:10000:1418145284747","sapId":"1101854","name":"INDIRA DEVU MD PC","createdBy":"Someone, Adam","dateAdded":"2014/12/09"},  {"id":"1667","issueId":"ezsats:10000:1418145284747","sapId":"1125031","name":"IL INDIRA DEVU MD PC","createdBy":"Someone, Adam","dateAdded":"2014/12/09"}]~' cell
                     from  dual
                  )
select  rtrim(regexp_replace(cell,'.*?"name":"([^"]*).*?}.','\1;'),';')
  from  data_cell
/


() The subexpression (a.k.a. a submatch or group) 
 and subexpressions may be nested to any depth.
 Parentheses (subexpresions) also capture the matched element into a variable that may be used as 
 a backreference. 
  (aka grouping or submatching) and their use as backreferences.
The following is a set of iteration metacharacters (a.k.a. quantifiers) that can control the number of times the preceding character is found in our searches. 
The iteration meta characters can also be used in conjunction with parenthesis meta characters.
. The . (period) means any character(s) in this position, for example, ton. will find tons, tone and tonneau but not wanton because it has no following character.
? The ? (question mark) matches when the preceding character occurs 0 or 1 times only, for example, colou?r will find both color (u is found 0 times) and colour (u is found 1 time).
* The * (asterisk or star) matches when the preceding character occurs 0 or more times, for example, tre* will find tree (e is found 2 times) and tread (e is found 1 time) and trough (e is found 0 times).
+ The + (plus) matches when the preceding character occurs 1 or more times, for example, tre+ will find tree (e is found 2 times) and tread (e is found 1 time) but NOT trough (0 times).

Hello

Like John said, if you want to talk about the suggestion of someone, then it makes more sense to respond to this proposal in the same thread.

Try to split the term complicated part smaller, easier to understand, like this:

Select rtrim (regexp_replace (cell

, '.*?'        || -any text (as low as possibble)

"« nom » : »" ||

'('          || -- \1 is ...

'[^"]*'  || -0 or more characters, but without quotes

')'          || -end \1

'.*?'        || -any text (as low as possibble)

'}.'            -a hug right, followed by any 1 character

, '\1;'

)

, ';'

)

of data_cell

;

This makes it more clear what you first do replaces

x 1 "name": "y' 'x 2}.   with a little

There

where x 1 and x 2 can be anything, except that you do not want 'something' to include another instance of the model that you are replacing.  That's why you should use

.*?  instead of simply

.*

The '?' after ' *' makes No greedy, i.e. when there is a game of choice, as little as possible.  (The default value for the regular expressions must be greedy, or match as much as possible.)

Note that this solution assumes there is exactly 1 "name" element in each set of braces.  For example, if you have a string like:

"[{'name': 'A', 'name': 'B', 'name': 'C', 'name': 'D'}, {'foo': 'bar'}]' he returned.

' ONE; [{'foo': 'bar'}] "The solution more complicated that I posted in response on the original thread #3 returns

' ONE; B; D"

Note also that none of them not what you asked.

Tags: Database

Similar Questions

Maybe you are looking for