0

I simply need to extract some info between two tags, in this case, <wsse:BinarySecurityToken>

For example:

<wsse:BinarySecurityToken att1="abc" att2="cd3"  att3="adfa">This is a text I need!!!===</wsse:BinarySecurityToken>

I tried

match = text.match(/<wsse:BinarySecurityToken[.*]>([^<]*)<\/wsse:BinarySecurityToken>/g)

does't work!

Or is there anything better than regex? I use angularJs 1

5
  • This is not duplicate. I do not want to use DOM/ActiveXObject. Commented Mar 28, 2017 at 5:50
  • Take a look at THIS. This should work I guess. Commented Mar 28, 2017 at 5:57
  • You should include in the question itself that it is for an ionic app, not in a comment to the answers (btw I deleted mine). But did you tried the DOMParser from your app ? I see plenty of examples online that make use of it, so I'd guess it's available even though I don't know ionic at all. Ps: I won't undelete my answer since if I'm correct, it's still a dupe. Commented Mar 28, 2017 at 5:58
  • The regex worked. Thanks @Kaiido anyway for your answer, I wanted to avoid DOM. Commented Mar 28, 2017 at 6:06
  • You should not try to avoid the right tools for the right job. Commented Mar 28, 2017 at 6:11

1 Answer 1

1

You want to do:

match = text.match(/<tag1.*>([^<]*)<\/tag1>/g)
Sign up to request clarification or add additional context in comments.

2 Comments

I have updated my question. Please can you answer for the updated question? I tried and this is not working!
Thanks this worked. I had to tweak it for my updated question , but this worked! /<wsse:BinarySecurityToken.*>([^<]*)<\/wsse:BinarySecurityToken>/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.