<title>
Ask a Question - Stack Overflow Ask a Question - Stack Overflow
</title>
when i was try to catch title empty. my pattern is
<title[^>]*>([^<]+)</title>
how can i remove empty lines or catch only title text?.
thank you
<title>
Ask a Question - Stack Overflow Ask a Question - Stack Overflow
</title>
when i was try to catch title empty. my pattern is
<title[^>]*>([^<]+)</title>
how can i remove empty lines or catch only title text?.
thank you
www.regexpal.com is a great utility for answering these types of questions. The m flag on a RegEx object will catch multiple lines nicely. This should match everything in between the title tags in the first matching group, even if it's multi-line, I always use the i flag as well, just to handle the unknowns if you're working with 3rd party data:
/<title>([^<]+)<\/title>/im
If you'd like the whitepsace removed (i.e. trim), you could do something like:
/<title>(?:\s+)?([^<]+)(?:\s+)?<\/title>/im
In either case, your first match group should have what you'd like:
myText.match(/<title>(?:\s+)?([^<]+)(?:\s+)?<\/title>/im)[1]