I have a xml file with these datas:
PONumber="HC01/1501/000001"
PONumber="HC01/1501/000002"
PONumber="HC01/1501/000003"
PONumber="HC01/1501/000004"
...
PONumber="HC01/1501/000100"
What i want is to delete 'HC01/1501/000001' until 'HC01/1501/000100'.
How to do it using regular expression to replace them with empty string
Thanks in advance
The below regex would replace chars present present with double quotes with an empty string.
Regex:
"[^"]*"
" - matches double quotes.
[^"]* - negated character class which matches any character but not of double quotes, zero or more times.
"- Matches the ending double quote.
So this matches a complete double quoted block. So by replacing the matched double quoted block with "" will give you the expected output.
Replacement string:
""
(?<=").*?(?=")
You can use lookaheads here.See demo.Replace by empty string
https://regex101.com/r/sJ9gM7/85
For each line you can replace the matches string of following regex
(?<==).*
With ''.
Demo
(?<=) is a positive look-behind and (?<==).* will match every thing after =.
If thats only the data that you have, use the RegEx /".*"/ and replacement as "".
Demo & Explanation
Else, use this RegEx: /"HC01\/1501\/000(0[0-9][0-9]|100)"/g
and the replacement string as "".
Demo & Explanation
Related
I am using this Regex in my Flutter App to find words enclosed by single-quotes that end with a .tr:
r"'[^'\\]*(?:\\.[^'\\]*)*'\s*\.tr\b"
Now I need another expression that is almost the same but looks for words enclosed by dobule-quotes, ending with .tr and might contain escaped single-quotes.
I tried simply changing the single quotes to double quotes from the first expression, but Flutter is giving me errors... I need to escaped some characters but I can not make it work. Any idea?
An edge case it should match is:
"Hello, I\'m Chris".tr
You may use this regex for double quoted text that can have any escaped character followed by .tr and word boundary:
r""""[^"\\]*(?:\\.[^"\\]*)*"\s*\.tr\b"""
RegEx Demo
you need to use \ before every " in your RegExp's source, try this:
RegExp regExp = new RegExp(r'\"[^\"\\]*(?:\\.[^\"\\]*)*\"\s*\.tr\b');
print("${regExp.hasMatch('"Hello, I\'m Chris".tr')}"); // result = true
I have the following regex:
/(?:[^\s"]+|"[^"]*")+/g
this works great for double quotes
How can I make it also match paired single quotes?
`a string 'keep together' or "keep together"`
becomes
`a`, `string` `'keep together'`, `or` `"keep together"`
You may use
/(?:[^\s"']+|"[^"]*"|'[^']*')+/g
^ ^^^^^^^^
The '[^']*' part will match a ', then any 0 or more occurrences of chars other than ', and then a '. A single quote must be added to the first negated character class, too.
See the regex demo
i want to use regex for replace a string in a file in powershell, this is the regex:
=.*\\app\\client\\.*\\
I applied this regex on that string:
HOME= C:\app\client\Administrateur\product
And i want this result:
= C:\app\client\Administrateur
But I have this result:
= C:\app\client\Administrateur\
How to say to regex i want to stop before the next backslash ?
Your pattern =.*\\app\\client\\.*\\ will match the last occurrence of \app\client\ and will then match until the last occurrence of the forward slash.
To match what comes after app\client\ but not include the last backslash you could use a negated character class matching not a backslash:
=.*\\app\\client\\[^\\]*
Regex demo
If the .* part at the start can not contain a backslash, this would be another option to prevent needless backtracking because the .* would first match until the end of the string:
=[^\\]*\\app\\client\\[^\\]*
Regex demo
I want to replace
$this->input->post("product_name");
with
$post_data["product_name"];
I want to use notepad++ regex, but I couldn't find proper solution
In find --> $this->input->post("[\*w\]");
In replace --> $post_data["$1"];
but its not working
The $this->input->post("[\*w\]"); pattern does not work because:
$ is a special char matching the end of a line, you need to use \$ to match it as a literal char
[\*w'\] is a malformed pattern as there is no matching unescaped ] for the [ that opens a character class. Also, w just matches w, not any letter, digit or underscore, \w does that.
You may use
Find What: \$this->input->post\("(\w*)"\);
Replace With: $post_data["$1"];
If there can be any char inside double quotes use .*? instead of \w*:
Find What: \$this->input->post\("(.*?)"\);
Regulex graph:
NPP test:
Use this pattern to match desired text \$this->input->post\(("[^"]+")\);
And replace it with pattern \$post_data\[\1\]
Explanation:
\$this->input->post - matach $this->input->post literally
\(("[^"]+")\); - match (literally, then match double quates and everything between them with "[^"]+" and store inside first capturing group, then match ); literally
To replace
$this->input->post("product_name");
by
$post_data["product_name"];
do replace, with regex activated
this->input->post\("(.*)"\);
by
post_data\["\1"\];
The \x with x a number, corresponds to the x-th match catched with the parenthesis. Here we catch any character inside this->input->post(XXXX);
Don't forget to escape special character with \.
Your special characters were []()
I want to write a regular expression that match string in quotes except quotes in my quotes.
For example:
My string:
"Good programm\",\"pls help"
I want to get:
Good programm\",\"pls help
Try (?<=").*(?=") check online: http://regexr.com?349d2
As long as you don't have nested structures you can try this:
(?<=")(?:[^"]|(?<=\\)")*(?=")
See it here on Regexr
(?<=") positive lookbehind assertion, ensures there is a " before the match (Try if it is working for you, in Regexr it is.)
(?:[^"]|(?<=\\)") Alternation: matches either a character that is not a ", or a " that is escaped (ensured by the lookbehind (?<=\\)).
* The character from the alternation is matches 0 or more times.
(?=") positive lookahead assertion, ensures there is a " after the match
But be careful: It matches across newlines and also between escaped ", when there are no non escaped quotes available.
Regexr