-1

I was wondering if my expression here can match the word cat or Cat only at the beginning of a line and if this also means that if there is a new line, it will also match, it is not just at the beginning of the entire chunk of text/string.

ex:

cat and

Cat

would highlight both instances at the beginning of the two lines

/^\b([Cc]at)\b/g  

My other, separate, question is, how do you match, let's say, 'cat', anywhere except for at the beginning of a line? How do you negate the beginning of line, but include all other instances?

ex:

cat likes cat and himself. 

would only match the second mentioning of the word cat.

Avinash Raj
  • 160,498
  • 22
  • 182
  • 229
user3295674
  • 793
  • 5
  • 16
  • 40
  • 1
    possible duplicate of [Reference - What does this regex mean?](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Mathletics Feb 03 '15 at 15:34

1 Answers1

1

You just need the multiline flag and ignoreCase flag can also be used to make your regex to

/^cat\b/gmi

as far as your optional question is concerned, if your regex supports lookbehind, then it would be

/(?<=.)cat/

if not

/.(cat)/

and take the Group 1.

Amit Joki
  • 53,955
  • 7
  • 67
  • 89