1

Could you point me out a PCRE RegEx that would match only the first letter of a string. I need to pass to Mongo DB, I'm concerning about performances at the moment I'm using ^a.

Examples:

MATCH

apple

alligator

NO MATCH

thanks

GibboK
  • 71,848
  • 143
  • 435
  • 658

2 Answers2

5

there are special tokens in PCRE to represent beginning and end of a string

/^a/ => will match all strings that start with "a"
keymone
  • 8,006
  • 1
  • 28
  • 33
2

You can use a start of string anchor ^.

^a
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452