Regex to extract data between two pipe symbols - regex

I am looking to extract "2" from the query parameter using Regex -
http://www.example.com?param=1|2|3|4|test&param1=5|6
Regex used -
.*param=.*\|(\w+)\|.*
The output I get is "4".
I have even tried this to no avail -
.*param=.*\|(.*?)\|.*
Any help is much appreciated.
Thanks

You need to make the first .* non-greedy:
param=.*?\|(\w+)\|
or make it not match a pipe:
param=[^|]*\|(\w+)\|

Using you regex, simply add a ? after .* to capture as less characters as possible :
.*param=.*?\|(\w+)\|.*

\|(\w+)\|
Try this .See demo.
http://regex101.com/r/rQ5jJ3/1

Related

Regex Pattern to extract url links from two string

I have two string in which I have to sorten urls. I want a regex pattern to extract them
https://l.facebook.com/l.php?u=http%3A%2F%2Febay.to%2F2EyH7Nq&h=ATNHM5kACc4rh_z68Ytw__cNCzJ63_iPezd_whc0PjcsN4qj1PfdJgFXyrOKM3-biqPm7eAXTOc5LD6r-7JXhRsqsqEHUs0jaJkjvm_QWf6sqbHQmS63q6P0_NcQoUa86Az5EttNT9xJb_evKBaiFxW7e7v2afJQn2zNxz5lQ8xgxhMcEFuJ3hUiSYUMEemKFB2LSIgAZFibRv4GeRrTk8hxFaArkBuAhQaXQFd4jX-aQuUYhjD0ErV5FY-D4gFMpb0lFCU7SyBlRpkUuOcHVjwjxN-_g6reMYwo8loAJnJD
/redirect?q=http%3A%2F%2Fgoo.gl%2FIW7ct&redir_token=PV5sR8F7GuXT9PgPO_nkBFLABQx8MTUxNjA3OTY5MEAxNTE1OTkzMjkw&v=7wmIyD1fM4M&event=video_description
Output will be from 1st and 2nd link:-
http%3A%2F%2Febay.to%2F2EyH7Nq
http%3A%2F%2Fgoo.gl%2FIW7ct
Please help me out.
I have already used:-
(http|https).*?&
but its not working on first url.
You can try this:
=(https?[^&]*)
Demo
If lookbehind is possible in your flavour of regex then you may try this as well which will ensure to not capture the equal sign:
(?<=)(https?[^&]*)
Demo 2
Try this regex !
I am also attach the output of the regex through regex101.
http%3A%2F%2F(.*)%2F(.*[^&])(?=&)
You can use this pattern to only capture goo.gl and ebay.to links:
(http%3A%2F%2F(ebay\.to|goo\.gl)%2F[^&]*)&
Demo

Notepad++ replace between .dodo? to </dada>

hey guys my regex skills suck and was looking for some help. I am using Notepad++ and am looking to easily replace everything between the following
example:
.dodo?ReplaceMe</dada>
Its in many lines i need to replace often so rather than hunting hightlighting and replacing i was hoping to score an easyier regex method that will save me time. The replace can include question mark if it makes it easier. Thanks in advance
You can match your pattern using \.dodo\?([^<]*)<\/dada>.
\.dodo\? matches .dodo? - you need to escape the . and ??
([^<]*) matches all characters aren't a <, ReplaceMe in this case, in a matching group
<\/dada> matches </dada> - you need to escape the /
View it in action here: https://regex101.com/r/bM2wE6/1
Use lookarounds:
(?<=\.dodo\?).*?(?=<\/dada>)
See it in action

How to build this regular expression?

Sample: AAAATGCCCTAAGGGATGTTTTAGAAA
I want to capture all string with these criteria:
Start: ATG
Follow by 3x characters of sets: A or C or G or T
End: TAA or TAG or TGA
Such as: ATGCCCTAA, ATGTTTTAG
I had a regular expression here: /[ACGT]*((ATG)(([ACGT]){3})+(TAA|TAG|TGA))[ACGT]*/g, but it only match the last ATGTTTTAG not ATGCCCTAA. I don't know why ?
Please help me write pattern that match both ATGCCCTAA and ATGTTTTAG.
Here is online example:
https://regex101.com/r/iO8lF9/1
This regex works well /(ATG(?:A{3}|C{3}|G{3}|T{3})(?:TAA|TAG|TGA))/g
as you can see here: https://www.regex101.com/r/gZ0zA9/2
I hope it helps
Using back-reference you can shorten your regex as this:
ATG([AGCT])\1{2}(?:TGA|TA[AG])
RegEx Demo
It matches [AGCT] after ATG and groups it as captured group #1. Next we match \1{2} to make sure same letter is repeated 3 times.
try...
^ATG[AGCT]{3}(TAA|TAG|TGA)$
I use this pattern and it works, thank all you for helping me.
/(ATG(:?A{3}|C{3}|G{3}|T{3})(:?TAA|TAG|TGA))/g

Regex replace keeping part of a string and adding data

I have this file with thousands of records (more thank 300.000) and I have to replace all the occurrences of a particular string but keeping some of it.
I'll give you an example, the string would be
\123
\34565
\923
..etc
so basically I would have to convert these strings in to
'|''|'123'
'|''|'34565'
'|''|'923'
does anyone have a quick solution for this?
Many thanks
Try this -
Regex - \\(\d+)
Replace with - '|''|'\1'
Demo here
Use this regex:
\\(\d+)
You should use g(global) modifier to match all. So your final regex would become:
/\\(\d+)/g
and replace it with:
'|''|'$1'
Demo:http://regex101.com/r/yO3xQ6

Find first point with regex

I want a regex which return me only characters before first point.
Ex :
T420_02.DOMAIN.LOCAL
I want only T420_02
Please help me.
You can use the following regex: ^(.*?)(?=\.)
The captured group contains what you need (T420_02 in your example).
This simple expression should do what you need, assuming you want to match it at the beginning of the string:
^(.+?)\.
The capture group contains the string before (but not including) the ..
Here's a fiddle: http://www.rexfiddle.net/s8l0bn3
Use regex pattern ^[^.]+(?=[.])