RegEx, Get first symbol "&" in String [closed] - regex

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have string :
/url?q=http://www.bbc.com/indonesia/berita_indonesia&sa=U&ved=0ahUKEwjhqsr6h73OAhVDu48KHTR1AKsQFghDMAs&usg=AFQjCNEv3lNjzDNxPjfpqOtOb0ApNzvCCA
I want to get the result like this :
http://www.bbc.com/indonesia/berita_indonesia
How can I do with using RegEx ?
Thanks

The first capturing group of the following expression will extract the part you want. \?q=([^&]+)

You can extract it with following regex:
/(http:\/\/.+)/
the first (and only) capturing group contains value of url.
Here you can see it in action and adjust for your prefferred language.
EDIT: this pattern will capture whole URL along with following query string. Do you need url with path and without query string?

Related

How to remove comma at end of extracted value? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am having the following String
{'Sample': '#it{tq}', 'Yield': 0.011063753491221462, 'Error': 0}
and I would like to extract the value from 'Sample', that means '#it{tq}'. I tried that using a regular expression: 'Sample':(\s*.+?\s)
but its giving me: '#it{tq}', including that comma at the end. Does anyone know how to erase the comma at the end?
this regular expression should do the job.
regex: 'Sample':\s*('[^']*')
https://regex101.com/r/DL5Ltq/2
how about using this:
'Sample': '(.*?)',
beware that the regex in the accepted answer cannot process the case having single quote escape text inside the capture group like this: {'Sample': '#it'{tq}'}.
If you use (.*?), it greedily process any single character inside two single quote.

Regex to select first two characters from string and remove rest of the string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to select first two characters appearing on a given string like below.
in below example i would like the result to show "CJ" only.
";2;14;1;1;CJ;1;CT;1;DG;1;DJ;1;DT;1;QF;1;QG;1;QH;1;TA;1;TG;1;TK;1;TR;1;TW;1;TX";
([a-zA-Z]{2})
(): Capture the string into a group
[a-zA-Z]: Match any letter, upper or lower case
{2}: Match exactly 2 times
Make sure the "global" flag is not enabled ("global" allows returning multiple matches, not just the first)

how to get string between two dots in ansible [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
this is part of my ansible hosts files:
[Arista]
Ars-898z.cnd0 arista_host=Ars-898z.cnd0.example.com
Ars-898y.mex0 arista_host=Ars-898y.mex0.exmaple.com
I want to somehow use filtering or regex to extract only cnd or mex (the string between first and second dot) in my ansible playbook and save it a variable such as "dcname" and use it create a folder.
Please let me know how I can do it. I have already searched stackoverflow but did not get any similar questions for ansible
How about this?
(?<=\.)[^.]+(?=\.[^.]*\.[^.]*$)
Regex101 demo.
Here is a more flexible solution:
(?<=\.)[^.]+(?=(?:\.[^.]*){3}$)
The 3 can be adjusted. It is the number of dots '.' that come after the matched substring. If you enter 2, you get "cnd0", if you enter 3, you get "cnd0 arista_host=Ars-898z".
Another demo.

C# Regex Replace string with Ignore specific word [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have File and I want to replace fix character * : ~ with # using regex but, it should not replace(ignore) B~~ word because, it need to remain as it is. Anybody have idea for that?
Input :
ABCHKLJNKL*dskjnsdfkdsmflkmdls
MLKMLKMLKMLKMLKMMML
zlmlkmm:skjnjnskfjnkjsdnkfjnkdjs
B~~KJNNKJNJNKKJNKJNFKKJNJNK
Output Should be :
ABCHKLJNKL#dskjnsdfkdsmflkmdls
MLKMLKMLKMLKMLKMMML
zlmlkmm#skjnjnskfjnkjsdnkfjnkdjs
B~~KJNNKJNJNKKJNKJNFKKJNJNK
Please provide regex because i want to done with one step.
Thanks
[*:]|(?<!B[~])[~](?![~])
Try this.This should do it.See demo.Replace by #.
https://regex101.com/r/tX2bH4/66

Another RegEx to match wanted result [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm having another issue where I want to extract values from a string. Please take a look.
string anotherTest = "Hello World [A12345 **(05,00,45)**] - [518.6Z] [51.5]"
I would like the result to return "A12345" "518.6Z" "51.5".
What I highlighted in bold is what I'm having issue with.
I'm using c# and I've tried [(\D?\d+.?\d+\D?)] ... which is fine if I don't have what's in parentheses.
You need to extract the first word from a [ ... ] substring. Use groups:
.*?(\[([^\[\] ]+).*?\])*
Then extract second group from all the captures (depending on your langauge)