how to get string between two dots in ansible [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 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.

Related

RegEx, Get first symbol "&" in 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 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?

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

i want to parse a string between two -'s by using regexp [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 want to parse the values between -. but for some data like 1st url contains -- so in that case i need to get the gap only and the next one i am able to get **camry** successfully by using *(site_data,'[^-]+',1,2)*. but i want to handle the gap as well.
U=Google--undefined|http://www.google.com/urlsa=t&rct=j&q=&esrc=s&frm=1&source=web&cd=2&ved=0CFMQFjAB&url=http://www.toyota.com/tundra/features.html&ei=-zwQUvOyGIXu2QWC7oGgBg&usg=AFQjCNFQKGcr2dbDeC-0zagtYdKFEfXXzQ&bvm=bv.50768961,d.aWc
U=Bing-camry-undefined|http://www.bing.com/searchq=camry&pc=MOZI&form=MOZSBR
Please help on this.
You can extract the string along with the hyphens, and then trim the hyphens.
trim('-' from regexp_substr(site_data,'-[^-]*-'))
Alternatively, you can also use regexp_replace function.
regexp_replace(site_data,'(-([^-]*)-)|(.)','\2')

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)

how to get first word after phrase with regex [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 9 years ago.
Improve this question
How do you find the first word after a string literal via regex?
I.e.
I want to extract "DAQJ7PS" from the line:
ERROR service.PostService - Failed to save post DAQJ7PS
/ERROR service\.PostService - Failed to save post (.+)/
will give you the result in the first capturing group. This can be tuned if you have more specific requirements.