-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
  • 172,303
  • 28
  • 230
  • 274
user3295674
  • 893
  • 5
  • 19
  • 42
  • 1
    possible duplicate of [Reference - What does this regex mean?](http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Evan Davis 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
  • 58,320
  • 7
  • 77
  • 95