#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    100
    Rep Power
    10

    Exclamation Using Regular Expression to Parse MICR Cheque data


    Hi,

    I have a string with MICR data from bank cheques.
    I want to parse this string using Regular Expressions, I am very new to regular expression. Am I in the right direction of using the regular expression to parse this?

    Following is sample data:

    -000044-1020-608-00527799400-
    -000412-1020-611-96866699410-
    -000381-1020-602-07320099400-
    -001743-1020-611-00158699010-
    -899123-1020-999-03060399000-08-00000311185-

    thanks
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,001
    Rep Power
    9398
    Actually you probably don't need them. Since they're all predictably long (they're all X or Y digits long, apparently) you can just use regular string methods to get the pieces you want.

    For example, the MMDD (I think) starts at the ninth character in for each one.
  4. #3
  5. Turn left at the third duck
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2011
    Location
    Nelson, NZ
    Posts
    112
    Rep Power
    93
    Hi juggernaut,

    requinix makes an excellent point. If your input all has the same shape, then substr() and its friends are your friends.
    Seeing that the last string in your input is longer, substr() still helps on shorter strings when you try to grab the faraway digits (returning FALSE), or you can use strlen().

    Nevertheless, for the sake of discussion, if your codes occurred at unpredictable locations in a file... Then yes, you are right that regular expressions would be a perfect tool for that.

IMN logo majestic logo threadwatch logo seochat tools logo