Ashwin Yaprala
Ashwin Yaprala

Reputation: 2777

Regular expression string between tags "<string>"

I have a string "<wpf><xaml><wpf-controls>". I need the string between the tags in array format. How do I get this?

Upvotes: 0

Views: 747

Answers (2)

B8vrede
B8vrede

Reputation: 4532

The regex for this problem is really simple it is: /<(.*?)>/

For the array part is would reference to the answer on how to use one line regular expression to get matched content

EDIT: for array of the insides of the tags use <wpf><xaml><wpf-controls>".scan(/(?:<(.*?)>)*/)

The (?: .. ) groups the tag together and the * says we want 0 or more of that group :)

Upvotes: 2

Tom De Leu
Tom De Leu

Reputation: 8274

'<wpf><xaml><wpf-controls>'.scan(/<(.*?)>/).map(&:first)

Upvotes: 0

Related Questions