java - regex to modify dynamic src attributes -
I am trying to use regex in a particular scenario as follows: < P> Many HTML pages, with the dynamic value We will filter the pattern What really is happening is very different. After the pattern is Here's the regex pattern I'm using Here is the code: Expected Result: Actual results: What really happens to your regex: This will match a quote character, followed by 1 or more events of any character followed by a You do not need to specify a regex to match the same event with & lt; Img src & gt; Each containing the number of tags:
tag1 = & lt; P & gt; Paragraph 1 & lt; Img src = "/ A / images /b.txt"> Some text & lt; / P & gt; Tag2 = & lt; P & gt; Paragraph 2 & lt; Img src = "/ a / b / images / cjpeg" & gt; Some text & lt; / P & gt; Tag 3 = & lt; P & gt; Paragraph 3 & lt; Img src = "/../ Images / H / E." & Lt; / p & gt; Tag 4 = & lt; p & gt; Paragraph 4 & lt; img src = "/../d / images / g / j / f.gif" & quot; & quot; Gt; Some text & lt; / p & gt;
"/ < Nothing & gt; / Images / target. What we need after replacement
Tag1 = & lt; P & gt; Paragraph 1 & lt; Img src = "/ library / MYFOLDER / location / b.txt" & gt; Some text & lt; / P & gt; Tag2 = & lt; P & gt; Paragraph 2 & lt; Img src = "/ library / MYFOLDER / location / c.jpeg" & gt; Some text & lt; / P & gt; Tag 3 = & lt; P & gt; Paragraph 3 & lt; Img src = "/ library / MYFOLDER / location / h / e page" & gt; Some text & lt; / P & gt; Tag 4 = & lt; P & gt; Paragraph 4 & lt; Img src = "/ library / MYFOLDER / location / g / j / f.gif" & gt; Some text & lt; / P & gt;
/ images eat everything and give us
tag 1 = & lt; P & gt; Paragraph 1 & lt; img src = "/ library / MYFOLDER / locationp> tag2 = & lt; p & gt; paragraph2 & lt; img src =" / library / MYFOLDER / locationp & gt; Tag 3 = & lt; P & gt; Paragraph 3 & lt; img src = "/ library / MYFOLDER / locationp>
" {1} {1,} [/ images /] {1} of & lt (.); Br>
string substringament = "<
Control step:
& lt; P & gt; & Lt; Strong & gt; Control step: & lt; / strong> & Lt; Img src = "/ library / MYFOLDER / location / maintenance_game.gif \" width = \ "20 \" & gt; . Details & lt; / P & gt;
& lt; P & gt; & Lt; Strong & gt; Control step: & lt; / strong>
[abc] matches a letter that is either
a ,
b , or
c ; This substrings do not match
"abc" . Therefore,
[/ images /] does not do that you think it does. Remove square brackets.
"{1} (.) {1,} [/ images /] {1}
/ ,
i ,
M ,
a ,
g ,
e ,
s . (Last
/ will be ignored after one of the sets you already have.) Also, when you ask to match one or more events of any character, the default This greedy match, matching as many characters as possible, therefore, it will be closed on the forefront of the square brackets instead of the nearest one place; and the top character < Try this regex instead of code: / in
and
"++ / images /
{1} , it does for you automatically . There is a shortcode for code> +
{1,} .
? Instead of the largest number, then it will search for the nearest
/ images / sub-code.
Comments
Post a Comment