Microsoft Word Find & Replace Wildcards (except this pattern) - replace

How can I use wildcards to find except this pattern.
For example, if the text is "html html>",
I can use "\<[a-zA-Z]#>" to find the pattern "<html>" or "<css>".
However, how can I find the opposite, excluding "<html>" or "<css>"?
"[!\<[a-zA-Z]#>]" does not return anything.

[!range] can only be used with a range inside, meaning you can't write a regex inside [!].
You could use it to do something like this : [!<][a-zA-Z]#[!>]
This will find every [a-zA-Z] that is not surrounded by <>

Related

Perl, replace multiple matches in string

So, i'm parsing an XML, and got a problem. XML has objects containing script, which looks about that:
return [
['measurement' : org.apache.commons.io.FileUtils.readFileToByteArray(new File('tab_2_1.png')),
'kpi' : org.apache.commons.io.FileUtils.readFileToByteArray(new File('tab_2_2.png'))]]
I need to replace all filenames, saving file format, every entry of regexp template, because string can look like that:
['measurement' : org.apache.commons.io.FileUtils.readFileToByteArray(new File('tab_2_1.png'))('tab_2_1.png'))('tab_2_1.png')),
and i still need to replace all image_name before .png
I used this regexp : .*\(\'(.*)\.png\'\),
but it catches only last match in line before \n, not in whole string.
Can you help me with correcting this regexp?
The problem is that .* is greedy: it matches everything it can. So .*x matches all up to the very last x in the string, even if all that contains xs. You need the non-greedy
s/\('(.*?)\.png/('$replacement.png/g;
where the ? makes .* match up to the first .png. The \(' are needed to suitably delimit the pattern to the filename. This correctly replaces the filenames in the shown examples.
Another way to do this is \('([^.]*)\.png, where [^.] is the negated character class, matching anything that is not a .. With the * quantifier it again matches all up to the first .png
The question doesn't say how exactly you are "parsing an XML" but I dearly hope that it is with libraries like XML::LibXML of XML::Twig. Please do not attempt that with regex. The tool is just not fully adequate for the job, and you'll get to know about it. A lot has been written over years about this, search SO.

Notepad++ replace text with RegEx search result

I would like replace a standard string in a file, with another that is a result of a regular expression. The standard text looks like:
<xsl:variable name="ServiceCode" select="###"/>
I would like to replace ### with a servicecode, that I can find later in the same file, from this URL:
<a href="/Services/xyz" target="_self">
The regular expression (?<=\/Services\/)(.*)(?=\" )
returns the required service code "xyz".
So, I opened Notepad++, added "###" to the "Find what" and this RegEx to the "Replace with" section, and expected that the ### text will be replaced by xyz.
But I got this result:
<xsl:variable name="ServiceCode" select="?<=/Services/.*?=" "/>
I am new to RegEx, do I need to use different syntax in the replace section than I use to find a string? Can someone give me a hint how to achieve the required result? The goal is to standardize tons of files with similar structure as now all servicecodes are hardcoded in several places in the file. Thanks.
You could use a lookahead for capturing the part ahead.
Search for: (?s)###(?=.*/Services/([^"]+)") and replace with: $1
(?s) makes the dot also match newlines (there is also a checkbox available in np++)
[^"] matches a character that is not "
The replacement $1 corresponds to capture of first parenthesized subpattern.
I am no expert at RegEx but I think I may be able to help. It looks like you might be going at this the wrong way. The regex search that you are using would normally work like this:
The parenthesis () in RegEx allow you to select part of your search and use that in the replace section.
You place (?<=\/Services\/)(.*)(?=\" ) into the "Find what" section in Notepad++.
Then in the "Replace with" section you could use \1 or \2 or \3 to replace the contents of your search with what was found in the (?<=\/Services\/) or (.*) or (?=\" ) searches respectively.
Depending on the structure of your files, you would need to use a RegEx search that selects both lines of code (and the specific parts you need), then use a combination of \1\2\3 etc. to replace everything exactly how it was, except for the ### which you could replace with the \number associated with xyz.
See http://docs.notepad-plus-plus.org/index.php/Regular_Expressions for more info.

Regex to find string starting with % and ending with .DESCR

I have a very large file of source code loaded in Notepad++, and I am trying to use it's regex search capabilities to find all places where a property is used.
I need to find all places where a property DESCR is set. I tried searching for just .DESCR without regex, but there are far too many results for me to sift through. I know that the code I am looking for will either be prefaced with %This. or & and some variable name, followed by .DESCR =.
I've tried using RegExr to construct the regex, but it isn't finding the strings I want. I've looked here to try to understand regex more, but I am missing something still.
EDIT: More descriptions
Here are examples of something I would be looking for:
%This.oPosition.DESCR = &DATAREC.Y_BUSINESS_TITLE.Value;
%This.data.DESCR = "";
&data.DESCR = "Analyst";
&oPosition.DESCR = &DATAREC.DESCR.Value;
It should not, however, match on these:
&P_NODE_PIN_DESCR = &NODE_PIN_DESCR;
&qLang.Descr = &sDescr;
I know that I am way off base, but here is what I have tried:
(\%This\.|\&[A-Z]+)\.DESCR = This doesn't pick up anything.
\%This.|\&(A-Z)+.DESCR This picks up on %This but nothing following, and doesn't find anything prefaced by &.
\%This.\w.DESCR =|\&\w+.DESCR = It looks like it's working on RegExr, but it doesn't match properly in Notepad++ (It matches on things like &ACCT_DESCR =)
I'm just not familiar enough with regex to understand what I am missing.
EDIT:
Notepad++ search settings:
You can search for (?:%this\.|&)\w+\.DESCR = according to your description. Please untick match case in the search dialog (except you are only searching for This, but not for this or similar.
(?:%this\.|&) matches either %this. or & both literally (but case insensitive)
\w+ matches one or more word characters, thus letters, numbers or underscore. You could also use [a-z]+ to be stricter and only consider letters - or [a-zA-Z]+ when searching case sensitive
\.DESCR = matches .DESCR = literally. If you only want to match DESCR case sensitive, you can use an inline modifier for case sensitivity: \.(?-i)DESCR =
Here's why your attempts didnt work:
You are checking for lowercase only. [A-Z] You need to check for [a-zA-Z] or use the insensitive modifier /i (in this case represented by the "match case" check box
When using the or simple it refers to everything after it until it reaches the end or a closed parentheses
Here's the regex you need
(\%This\.|\&)[A-Za-z]+\.DESCR
If you want to capture only .DESCR you can use this non-capturing groups like so:
(?:(?:\%This\.|\&)[A-Za-z]+)(\.DESCR)
You can then use the back-reference $1 or \1 to replace .DESCR in these specific appearances
https://regex101.com/r/fW9lZ2/2

Regex for the value of an HTML Property

I have a load of links that look like this:
Taboola - Content you may like
I want to delete the entire ICON and ADD_DATE attributes and their values.
I'm using sublime with a regex find/replace but I'm not sure how to write the regex to grab everything in between ICON=" AND "
Any help would be appreciated!
This should work (escaping quotes as necessary):
ICON="[^"]*"
The reason ICON=\"(.*)" won't work is that regex can 'be greedy' in what it takes. This means that if it can match more of the string to satisfy the pattern it will.
You can either specify a non greedy search, such as ICON=".*?" or explicitly declare matches on atoms that are not quotes as in the above answer.

How to match a string that does not end in a certain substring?

how can I write regular expression that dose not contain some string at the end.
in my project,all classes that their names dont end with some string such as "controller" and "map" should inherit from a base class. how can I do this using regular expression ?
but using both
public*.class[a-zA-Z]*(?<!controller|map)$
public*.class*.(?<!controller)$
there isnt any match case!!!
Do a search for all filenames matching this:
(?<!controller|map|anythingelse)$
(Remove the |anythingelse if no other keywords, or append other keywords similarly.)
If you can't use negative lookbehinds (the (?<!..) bit), do a search for filenames that do not match this:
(?:controller|map)$
And if that still doesn't work (might not in some IDEs), remove the ?: part and it probably will - that just makes it a non-capturing group, but the difference here is fairly insignificant.
If you're using something where the full string must match, then you can just prefix either of the above with ^.* to do that.
Update:
In response to this:
but using both
public*.class[a-zA-Z]*(?<!controller|map)$
public*.class*.(?<!controller)$
there isnt any match case!!!
Not quite sure what you're attempting with the public/class stuff there, so try this:
public.*class.*(?<!controller|map)$`
The . is a regex char that means "anything except newline", and the * means zero or more times.
If this isn't what you're after, edit the question with more details.
Depending on your regex implementation, you might be able to use a lookbehind for this task. This would look like
(?<!SomeText)$
This matches any lines NOT having "SomeText" at their end. If you cannot use that, the expression
^(?!.*SomeText$).*$
matches any non-empty lines not ending with "SomeText" as well.
You could write a regex that contains two groups, one consists of one or more characters before controller or map, the other contains controller or map and is optional.
^(.+)(controller|map)?$
With that you may match your string and if there is a group() method in the regex API you use, if group(2) is empty, the string does not contain controller or map.
Check if the name does not match [a-zA-Z]*controller or [a-zA-Z]*map.
finally I did it in this way
public.*class.*[^(controller|map|spec)]$
it worked