Reputation: 2133
I have text like the following :
<p class="field">[text text1 "text2"] </p>
which i want to get text1 and text2 and replace them in the below text
<p>[text text1 text2] <br/></p>
How can i do that ?
Upvotes: 2
Views: 137
Reputation: 990
Search <p class="field">\[(\S+ \S+) "(\S+)"\] </p>
, and replace with <p>[\1 \2] <br/></p>
Upvotes: 1
Reputation: 55649
Untested, but I think this should do it.
I'm assuming the exact formatting, no room for more or less spaces anywhere. And that text
, text1
and text2
can be anything.
Replace:
<p class="field">\[([^ ]+) ([^ ]+) "([^"]+)"\] </p>
with:
<p>\[\1 \2 \3\] <br/></p>
Explanation:
You may want to consider replacing the space characters in Replace with \s
(white-space) for a more generic solution.
\[
and \]
- escaped [
and ]
[^ ]
- not a space
[^ ]+
- one or more characters that aren't spaces
[^"]
- not a "
[^"]+
- one or more characters that aren't "
\1
- gives the string that corresponds to the first thing in brackets (i.e. ([^ ]+)
)
\2
- gives the string that corresponds to the second thing in brackets (i.e. ([^ ]+)
)
\3
- gives the string that corresponds to the third thing in brackets (i.e. ([^"]+)
)
Upvotes: 5