Hello I need a help with my text which is like this
Text1|Text2|Text3|Text4|Text5|Text6|Text7|Text8|Text9|Text10
So the text need to change it to like this:
Text8|Text5|Text4|Text9|Text10|Text7
So change these texts postions and remove Text 1,2,3,6
With regex you can use capture groups to replace stuff. In your case it might look like
find
(Text1)\|(Text2)\|(Text3)\|(Text4)
replace
$2|$1|$4|$3
will result in
Text2|Text1|Text4|Text3
So just apply this technique to your longer string and it should work just fine. Assuming you know how to order the results.
Related
I have the following text, for example:
nino&searchPhrase=jn123456&alphabetical
And I want to extract jn123456.
I've put together the following regex to extract NINOs:
(\bnino?\b.*?|Nino?\b.*?)[a-zA-Z]{2}[0-9]{6}
The problem I have is at the very end of the regex where I'm matching the last alpha character which may or may not be there.
I've tried adding the following at the end of the regex shown above without any luck:
?[a-zA-Z]{1} and
[?a-zA-Z]{1}
Could someone please look at this and let me know where I've gone wrong.
Many thanks and kind regards
Chris
You may use something like this:
^[Nn]ino&?\w*=([a-z]{2}\d{6})
which will capture "jn123456" in the first capturing group.
Demo.
If the character & can be anything else, then you may use . instead.
I am at the beginning of learning Regex, and I use every opportunity to understand how it's working. Currently I am trying to extract dates from a text file (which is in fact a vnt-file type from my mobile phone). It looks like following:
BEGIN:VNOTE
VERSION:1.1
BODY;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:18.07.=0A14.08.=0A15.09.=0A15.10.=
=0A13.11.=0A13.12.=0A12.01.=0A03.02. Grippe=0A06.03.=0A04.04.2015=0A0=
5.05.2015=0A03.06.2015=0A03.07.2015=0A02.08.2015=0A30.08.2015=0A28.09=
17.11.2017=0A
DCREATED:20171118T095601
X-IRMC-LUID:150
END:VNOTE
I want to extract all dates, so that the final list is like that:
18.07.
14.08.
15.09.
15.10.
and so on. If the date has also a year, it should also be displayed.
I almost found out how to detect the dates by the following regex:
.+(\d\d\.\d\d\.(2015|2016|2017)?).+
But it only detect very few of the dates. The result is this:
BEGIN:VNOTE
VERSION:1.1
15.10.
04.04.2015
30.08.2015
24.01.2016
DCREATED:20171118T075601
X-IRMC-LUID:150
END:VNOTE
Then I tried to add a question mark which makes the .+ not greedy, as far as I read in tutorials. Then the regex looks like:
.+?(\d\d\.\d\d\.(2015|2016|2017)?).+?
But the result is still not what I am looking for:
BEGIN:VNOTE
VERSION:1.1
21.03.20.04.18.05.18.06.18.07.14.08.15.09.15.10.
13.11.13.12.12.01.03.02.06.03.04.04.20150A0=
03.06.201503.07.201502.08.201530.08.20150A28.09=
28.10.201525.11.201528.12.201524.01.20160A
DCREATED:20171118T075601
X-IRMC-LUID:150
END:VNOTE
For someone who is familiar with regex I am pretty sure this is very easy to solve, but I don't get it. It's very confusing when you are new to regex. I tried to find a hint in some tutorials or stackoverflow posts, but all I found is this: Notepad++ how to extract only the text field which is needed?
But it doesn't work for me. I assume it might have something to do with the fact that my text file is not one single line.
I have my example on regex101 too.
I would be very thankful if maybe someone can give me a hint what else I can try.
Edit: I would like to detect the dates with the regex and as a result have a list with only the dates (maybe it is called substitute?)
Edit 2: Sorry for not mentioning it earlier: I just want to use the regex in e.g. Notepad++ or an online regex test website. Just to get the result of the dates and save the result in a new txt-file. I don't want to use the regex in an programming language. My apologies for not being precisely before.
Edit 3: The result should be a list with the dates, and each date in a new line:
I want to extract all dates, so that the final list is like that:
18.07.
14.08.
15.09.
15.10.
I suggest this pattern:
(?:.*?|\G)(\d\d\.\d\d\.(?:\d{4})?)
This makes use of the \G flag that, in this case, allows for multiple matches from the very start of the match without letting any single unmatched character in the text, thus allowing the removal of all but what's wanted.
If you want to remove the extra matches as well, add |.* at the end:
(?:.*?|\G)(\d\d\.\d\d\.(?:\d{4})?)|.*
regex101 demo
In N++, make sure the options underlined are selected, and that the cursor is at the beginning. In the picture below, I replaced then undid the replacement, only to show that matches were identified (16 replacements).
You can try using the following pattern:
\d{2}\.\d{2}\.(?:\d{4})?
This will match day.month dates of the form 18.07., but it also allows such a date to be followed by a four digit year, e.g. 18.07.2017. While it would be nice to make the pattern more restrictive, to avoid false fire matches, I do not see anything obvious which can be added to the above pattern. Follow the demo link below to see the pattern in action.
Demo
I have an XML file that has 9000 lines in it.
Each XML node has about 10 attributes in it.
One of the attributes is:
<CreatedDate>2009-10-26T02:39:24</CreatedDate>
What I need to do is change the format of the DateTime to:
<CreatedDate>27/05/2010 07:30:16</CreatedDate>
But I do not know how to do it.
I know I could write a Regex to identify each value that needs to be replaced, but how can make it only change the values I want and maintain the rest?
I have thought about writing a macro, but the document is too big to format in a way that I could predict where the element I want ot change is, and searching for something does not seem to work on a macro.
Any ideas? - I am sure it can be done.
If you want to change datetimes format only inside <CreatedDate> tags, try the regex replace in Notepad++ like this:
Replace this:
<CreatedDate>(\d{4})\-(\d{2})\-(\d{2})T([\d\:]*)</CreatedDate>
With this:
<CreatedDate>$3/$2/$1 $4</CreatedDate>
We refer to each parentheses using a $ symbol and it's position, so we can use those values in the replacing result.
Find:
<CreatedDate>(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)</CreatedDate>
Replace:
<CreatedDate>\3/\2/\1 \4:\5:\6</CreatedDate>
\d matches a Digit.
And the braces create a group that you reference with e.g. \1
Find this
<CreatedDate>(\d{4})-(\d{2})-(\d{2})T(\d{2}:\d{2}:\d{2})<\/CreatedDate>
Replace with:
<CreatedDate>\3/\2/\1 \4<\/CreatedDate>
I want to find and replace text between to hash comments. e.g I want to find if there is a text something like below within #string_start and #string_end
#string_start
this could be any text here
and here
#string_end
I tried this code but it didn't work and I know I am not using the corrent syntax due to my lack of regex knowledge.
\#string_start(.*?)\#string_end
#string_start\n([\s\S]*?)#string_end
Try this.Grab the capture.See demo.
https://regex101.com/r/vD5iH9/61
In the example below, I need to change everything before the final slash to jreviews/
so in the example below the first line would become
jreviews/159256_0907131531001639107_std.jpg
i am using open office find and replace tool, I see there is an option for regex but i dont know how to do this. How can I find and replace the img.agoda urls and everything thats a number and slash, and replace that with jreviews/ ?
but keeping the numbers after that final slash, because these are the filename.
http://img.agoda.net/hotelimages/159/159256/159256_0907131531001639107_std.jpg
http://img.agoda.net/hotelimages/161/161941/161941_1001051215002307125_std.jpg
http://img.agoda.net/hotelimages/288/288595/288595_111017161615_std.jpg
http://img.agoda.net/hotelimages/289/289890/289890_13081511070014319856_std.jpg
http://img.agoda.net/hotelimages/305/305075/305075_120427175058_std.jpg
http://img.agoda.net/hotelimages/305/305078/305078_120427175537_std.jpg
Regex seems like overkill, at least for your examples. Since they all have the same number of subfolders, a simple Find and Replace with wildcards works for me. Here's how I did it in Excel:
Just replace http://*/*/*/*/ with jreviews/.
Try this:
Replace the below match with "CustomName/"
^.+[/$]