Problem with find / replace with wildcards. Will put in the same Regular expression twice
-
I have a document like this:
$node->field_it_themenueberschrift_dt $node->field_it_themenueberschrift_2 $node->field_it_themenueberschrift_3 $node->field_it_themenueberschrift_4 $node->field_it_thementext_dt $node->field_it_thementext_2 $node->field_it_thementext_3 $node->field_it_thementext_4 $node->field_it_qr_code_dt $node->field_it_qr_code_2 $node->field_it_qr_code_3 $node->field_it_qr_code_4
I would like to put a div container with class appanding to the name of variable arround it like this:
For example it should look like this:
<div class='qr_code_4'>$node->field_it_qr_code_4</div>
I tried this way:
search:\$node->field_it_(.*?)
replace with:<div class='(\1)'>$node->field_it_(\1)</div>
I get:<div class=''>$node->field_it_</div>themenueberschrift_dt <div class=''>$node->field_it_</div>themenueberschrift_2 <div class=''>$node->field_it_</div>themenueberschrift_3 <div class=''>$node->field_it_</div>themenueberschrift_4 <div class=''>$node->field_it_</div>thementext_dt <div class=''>$node->field_it_</div>thementext_2 <div class=''>$node->field_it_</div>thementext_3 <div class=''>$node->field_it_</div>thementext_4
What did I wrong?
-
You matched an empty string with the ungreedy expression
(.*?)
. Try this instead:Search: (?-s)(\$node->field_it_(.*))$ Replace: <div class='($2)'>$1</div>
Hope this helps
-
@astrosofista said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:
<div class=‘($2)’>$1</div>
Hey You are my hero. ;-)
This is the solution.But whre can i find the documentation for this?
I know the expression $2 from htaccess and other script languages.
But for Notepad i found the solution with (\1).
And the (?-s) expression i did not find.
It is to avoid hungry behavior?
Like -U with PHP preg_replace?Until now I worked with Textpad-Editor.
There i would do it with &
But notepad has better Syntax Highlighting. Therefor i would like to learn more.Thank You very much.
-
@Regina-Oswald said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:
But whre can i find the documentation for this?
The Notepad++ user manual is one place.
See https://npp-user-manual.org/
And specifically for searching, see https://npp-user-manual.org/docs/searching/
And very specifically for regular expressions see https://npp-user-manual.org/docs/searching/#regular-expressions -
Glad I could helped you. You were really close to a working solution. Also the issue were clearly explained. Thank you for that, makes easier for us to help people.
Concerning the documentation, you can read the regex guide in the FAQ section of this forum, which also includes links to more advanced docs.
$n
and\n
means the same, they are references to groups, just I am used to the first one.And the
(?-s)
expression overrules the. matches newline
option, so one is sure that the all text will not be considered as a single line, which will be correct on the example data you provided. -
@Alan-Kilborn said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:
The Notepad++ user manual is one place.
Thanks also to You.
I seeked half day for the links to doc and found only very old docs ore broken links.
Obviously I did not have the right search terms. -
@Regina-Oswald said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:
I seeked half day for the links to doc and found only very old docs ore broken links.
Well, if you go to Notepad++ 's home site:
https://notepad-plus-plus.org/There appears a link there called “Online Help” and if you click that there will be a link to the user manual that I shared the link of earlier.
Not all that difficult to find.
OR…
In Notepad++ 's
?
menu, there is an entry forOnline Documentation
that will take you there as well:This stuff is about as easy/difficult to find as the site we’re now on, so…
-
Hello, @regina-oswald, @astrosofista, @alan-kilborn and All,
@regina-oswald, here is my version of your goal :
SEARCH
(?-s)^\$node->field_it_(.+)
REPLACEMENT
<div class='\1'>$0</div>
Notes :
-
In search, the
(?-s)
in-line modifier forces a.
to be an unique standard character ( not a line-break char ) and the+
syntax represents the{1,}
quantifier, meaning all the remaining chars of current line, after the>field_it_
string -
In replacement, the
$0
syntax stands for the overall match so, in your case, for each complete line, without its line-break char(s)
Best Regards,
guy038
-
-
@guy038 said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:
SEARCH (?-s)^$node->field_it_(.+)
REPLACEMENT <div class=‘\1’>$0</div>Thanks also to You.
Interesting. -
@Alan-Kilborn said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:
This stuff is about as easy/difficult to find as the site we’re now on, so…
I found the online-Documentation but not the special goal with twice repleacing of the same regular expression.
-
@Regina-Oswald said in Problem with find / replace with wildcards. Will put in the same Regular expression twice:
but not the special goal with twice repleacing of the same regular expression
I’m actually not sure what you are meaning by that.
I suspect it might mean something very specific to the replacement you wanted to do.
The documentation is only going to describe the capabilities; it can’t possibly describe all possible application nuances of those capabilities.