I am struggling with a generic regex to switch values around.
I want a quick way to rearrange
{"AAA","AA1"},
into
{"AA1","AAA"},
ideally using notepad++
Cheers.
Open Replace with Ctrl+H & tick the Regular Expression box
Find: \{(.*),(.*)\}
Replace With: {\2,\1}
(Assumes no } in the quoted values)
in notepad++ :
find :
\{\s*\"(.*?)\"s*\,\s*\"(.*?)\"\s*}
replace by :
{"\2","\1"}
Try this one:
Search: (\{\s*")([^"}]*)(",\s*")([^"}]*)("\})
Replace: \1\4\3\2\5
Pattern: \{("[^"]*")\s*,\s*("[^"]*")\}
Replacement: {$2,$1}
Explanation:
group the "..." parts
use the inverse character class [^"]* to match everything until the first "
reverse their orders with the backreferences: {$2,$1}
Related
Given this example text:
<abr:rules>
<abr:ruleTypeDefinition>
<abr:code>ABB</abr:code>
<abr:ownership>
<abr:owner organization="NT" application="DCS" subapplication="FM"/>
...lines...
...........
</abr:rules>
<abr:rules>
<abr:ruleTypeDefinition>
<abr:code>ADE</abr:code>
<abr:ownership>
<abr:owner organization="NT" application="DCS" subapplication="CM"/>
...lines...
...........
</abr:rules> (end of group)
I would like to find and remove all that goes from <abr:rules> to </abr:rules> with the condition that subapplication IS NOT "CM". Organization and application are the same, <abr:code> it's any string.
What I tried so far is
<abr:rules>\n<abr:ruleTypeDefinition>\n<abr:code>[a-zA-Z0-9]{3,}<\/abr:code>\n<abr:ownership>\n<.*"(FM|PSD|SSC)"\/>\n(?s).*?\n<\/abr:rules>\n
which works but only because I know the other subapplication names.
Is there any way to do it with Regex only ?
Try the following find and replace:
Find:
<abr:rules>((?!subapplication=).)*subapplication="(?!CM")[^"]+"((?!</abr:rules>).)*</abr:rules>
Replace:
(empty string)
Demo
Note: The above pattern will only work if you enable dot in Notepad++ to match newlines. If you don't want to do that, then you may use [\S\s] instead of dot.
You should not use regex for xml, you can read why here:
https://stackoverflow.com/a/1732454/3763374
Instead you can use some parser like Xpath
I'm trying to select text between ></ . Example below I want "text"
>text</
but I'm unable to do so.
tried the following but it doesn't like the slash at the end of the regex
\>(.*?)\<\
I'm trying to do this in TextPad. How is this supposed to be done?
I'm ultimately wanting to delete all text between these two characters so all I'm left with is something like: <element></element>
RegEx wise, you can use 3 groupings and for the replace only use the first and 3rd group: \1\3.
Find: (>)(.*)(</)
Replace: \1\3
Try doing:
\>(.*?)\<\/
The regex that you were trying would actually have given error because you had a \ and nothing after that.
You are close.. use the following:
(>).*?(<\/)
And replace with \1\2
See DEMO
OR
You can use lookbehind and lookaheads:
(?<=>)(.*?)(?=<\/)
And replace with '' (empty string)
See DEMO
I have this:
1200
3701
Trying to get this:
100ct1200
100ct3701
But got this:
100ct([0-9])([0-9])([0-9])([0-9])
Because I used regex in find & replace:
Find: ([0-9])([0-9])([0-9])([0-9])
Replace: 100ct([0-9])([0-9])([0-9])([0-9])
Actually I don't know how to express it to just add 100ct infront of the numbers and leave the rest as-it-is. Help? Thanks!
You need to use the following syntax
Find: (([0-9])([0-9])([0-9])([0-9]))
Replace: 100ct\1
Note the parentheses around the whole find expression: \1 refers to their content.
EDIT:
You can also use some shorthands for the Find expression:
Find: (\d{4})
It means "match 4 digits".
Your find and replace commands should be,
Find: ([0-9][0-9][0-9][0-9])
Replace: 100ct$1
$1 or \1 or #1 according to your tool.
Find: ([0-9][0-9][0-9][0-9])
Replace: 100ct$1 or 100ct\1 depending on the language (not sure what syntax Notepad++ uses).
Demo: http://regex101.com/r/cT1mJ8/1
I need to replace hundreds of if (ereg("avion","$keyw")) by if (preg_match("#avion#","$keyw")) {
I tried this:
1st : ereg\("(.*)"
2nd : preg_match\("#$1#"
But it replaces the first group by '$1'... Any idea please?
This is working on the UltraEdit version I have:
I'm just not sure why you have # in your replace.
You can pick "Current file" for all instead of the "Selected Text" I used for the comparison.
Another thing to note, it might be safer to use:
ereg\("(.*?)",
Replace:
preg_match("#$1#",
Using sed you can try this way:
sed -i".bak" 's/(ereg("\([a-z]*\)","\$keyw"))/\(preg_match\("#\1#","$keyw"\)\)/' filename
EDIT: Updated to match any word, not only 'avion'
I have the following example:
assert(apply_patch_check("/system/app/ApplicationsProvider.odex", "31bdc8cc9a131131f97a931933723c0fa6c786ba", "c996ebe1ab91e780dc9b6a41c18214c633413dc4"));
set_progress(0.000153);
assert(apply_patch_check("/system/app/AtciService.odex", "09003fce87c178afb603f4ad7fd9db2e612d0648", "aa28dfd656fd12f38f904f85f85f432a822e7719"));
set_progress(0.000386);
what I need is only:
/system/app/ApplicationsProvider.odex
/system/app/AtciService.odex
How to do that with notepad++
Find what: ^[^"]*"([^"]*).*$
Replace with: \1
Basically use first and second quotation mark to extract text that is in between them.
Try this one too
Find what: (sys.*dex)|.\s? or .*(sys.*dex).*\W
Replace with: $1