dimanche 20 septembre 2020

Extract And capture Elements in a string using RegEx, and determining using a conditional if the regex will work for a given string

While Developing in Go, How Would one Given a string extract certain elements between "%" and then capture the substring to the right of the last "%" as one element? How would one Also Check if the Regex operation can be performed to the given string?

Ex: 
This is %StackoverFlow% and it's a %Phenomenal%  "$ resource
$ presentations and got credit for it. I brought this up to  $
$ were She looked at me and said. She looked at me and said, $

Now I'd Like to get

element 1: StackoverFlow

element 2: Phenomenal

element 3:  "$ resource
$ presentations and got credit for it. I brought this up to  $
$ were She looked at me and said. She looked at me and said, $

What I've Accomplished to do So far, this expression will capture the two elements inside "%"

\%(.*?)\%

But I can't figure out how to proceed to capturing everything to the right of the element as a single capture within the same Regex Expression?

#2) How can we create a conditional to determine the String contains a substring with %content%? E.g.

This is StackOverFlow

This String does not contain "%" with content between it, is there a way the we can determine if the regex will work on this string above?

Aucun commentaire:

Enregistrer un commentaire