0

I am trying to get the value of the first letter in my array. For some reason its just chopping off my first letter. Will someone please tell me where I am going wrong?

<cfset MidInitial = "Hugh" />
<cfset MidInitArray = ReMatch("[a-z]",MidInitial) />
<cfdump var="#MidInitArray#" />

Array Hugh
[1] u
[2] g
[3] h

Where is the H going?!

4
  • 1
    ReMatch is case sensitive. Either use (?i) infront of your regex or add [A-Za-z] in your regex or do you just want the first character in the string? If so, you don't need regex for this and a Left(MidInitial,1) would work. Commented Feb 9, 2015 at 20:09
  • Perfect that's what I was looking for if you want to post as an answer Commented Feb 9, 2015 at 20:14
  • 1
    Is there a reason why you are not simply using left()? Commented Feb 9, 2015 at 20:40
  • What do you want to do with values like 0'Donnell and O'Donnell? Commented Feb 9, 2015 at 20:52

1 Answer 1

2

ReMatch is case sensitive. Either use (?i) infront of your regex or add [A-Za-z] in your regex.

Do you just want the first character in the string? If so, you don't need regex for this and a Left(MidInitial,1) would work.

Sign up to request clarification or add additional context in comments.

1 Comment

Or ReMatchNoCase() with the same regex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.