![]() Now, let's use this dumb regex over it: \b(\S)(\S)(\S)(\S*)\b Consider the following text: Lorem ipsum dolor sit amet consectetuer feugiat fames malesuada pretium egestas. The difference is that the first one uses the name to match the value, and the second one uses the group index (which starts at 1). Both regexes do the same thing: they use the value from the first group (the name of the tag) to match the closing tag. The first regex has a named group (TAG), while the second one uses a common group. ![]() You want to parse the tags, so you could do something like this (I have added spaces to make it easier to understand): \.+?)\> [^\> Imagine you have some kind of XML or HTML (be aware that regex may not be the best tool for the job, but it is nice as an example). They can help you to extract exact information from a bigger match (which can also be named), they let you rematch a previous matched group, and can be used for substitutions. The parser uses it to match the text, but ignores it later, in the final result.Īs requested, let me try to explain groups too. See? The first group has not been captured. So, I change the regex to include the non-capturing group (?:). I would get the following result: Match ""īut I don't care about the protocol - I just want the host and path of the URL. ![]() ![]() Let me try to explain this with an example. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |