Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Help me in writing regular expression

Last post 07-23-2009, 5:21 AM by komandin.alexander. 5 replies.
Sort Posts: Previous Next
  •  06-17-2009, 10:02 AM 54030

    Help me in writing regular expression

    I have a requirement where I have to fetch prefix in a text excluding right hand side digit pattern.

    For ex: AB9T0005 should give me only AB9T

    AB9T-K1A-0005 should give me only AB9T-K1A-

    What I mean is prefix may include any input including numbers and other alpha numeric values.

    With out using regular expression I will parse from right to left till I find non numeric value and will take substring of it.

    I have used following regular expression \b(?<=.*)\d*\b but of no use?

    It is failing for this input abc123

    Can any one help me in this?

    Thanks in Advance

    Naga

     

  •  06-17-2009, 11:30 AM 54033 in reply to 54030

    Re: Help me in writing regular expression

    You could try:

    ^.*\D+


  •  06-17-2009, 11:33 AM 54034 in reply to 54030

    Re: Help me in writing regular expression

    chambarish:

    I have used following regular expression \b(?<=.*)\d*\b but of no use?

    It is failing for this input abc123

    I'm not sure of what you were thinking that pattern would do but I get the impression you don't really understand how look-arounds work. And since you made no mention of what language you are doing this in as requested in the posting guidelines there's no way to know if you can even use look-behinds.

    the pattern

    .*\D

    will perform your task against the provided samples.


    Michael

    "In theory, theory and practice are the same. In practice, they are not."
    Albert Einstein
  •  06-17-2009, 10:56 PM 54055 in reply to 54030

    Re: Help me in writing regular expression

    It worked.

    Thank you very much for your kind help.

    Naga.

  •  07-23-2009, 5:18 AM 55364 in reply to 54030

    Re: Help me in writing regular expression

    Text

    AB9T0005
    AB9T-K1A-0005

    Regex

    .*\w[^\d\s]

    Result:

    AB9T
    AB9T-K1A-

    Look at examples

    http://komandin.org/regex/regex_view.html

     

  •  07-23-2009, 5:21 AM 55365 in reply to 55364

    Re: Help me in writing regular expression

     mash's regex the best 

     

    .*\D

View as RSS news feed in XML