Members don't see the ad below. Register now!

I was trying out some regular expressions shown in NLPclass using regextester website.I used the following string

The other one,the blithe one

When I used the regex [^a-zA-Z][Tt]he[^a-zA-Z] , only the word 'the' after the comma got matched.

But when I put a space in front of the whole sentence( just before 'The'), the two words 'The' at the beginning and 'the' after comma got matched.

I cannot understand why the regex failed to do the match for 'The' at the start of sentence ,why do I have to introduce another character.

In the course video,Prof.J gets the correct results because there was a string in the previous line.If there wasn't,then 'The' at the beginning of the sentence won't match.

asked 10 Mar '12, 00:05

aikid's gravatar image

aikid
2.9k541


It's because you tell it to match a character before T. When it says don't match these characters it is actually saying 'match a character but not one of these,' hence putting a space in front means the condition is satisfied.

link

answered 10 Mar '12, 00:15

fnenu's gravatar image

fnenu
81111

Your answer
toggle preview

Follow this Question via Email

Once you sign in you will be able to subscribe for any updates here

Q&A Editor Basics

  • to upload an image into your question or answer hit
  • to create bulleted or numbered lists hit or
  • to add a title or header hit
  • to section your text hit
  • to make a link clickable, surround it with <a> and </a> (for example, <a>www.google.com</a>)
  • basic HTML tags are also supported (for those who know a bit of HTML)
  • To insert an EQUATION you can use LaTeX. (backslash \ has to be escaped, so in your LaTeX code you have to replace \ with \\). You can see more examples and info here

powered by OSQA