0

I'm trying write regex to converts lt34 or Lt34 or lT34 and lt 34 or Lt 34 or lT 34 to Lt34 and Lt 34 respectively using one regex. 34 is just a numeric value and can be anything but the text "lt" is fix with any casing which should be converted to "Lt"(camel casing using regex).

I'm not able to write regex as I'm very new to it. Please help me.

Ataur Rahman Munna
  • 3,887
  • 1
  • 23
  • 34
Raj Bhatia
  • 1,049
  • 4
  • 18
  • 37
  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: [ask] – Thomas Ayoub Apr 03 '17 at 13:14
  • hi, you can try /lt(?:[\s])*[\d]+/Lt $1/gi – volkinc Apr 03 '17 at 18:30
  • No, I have tested it, its not working. Could you please provide implemented small java code.? – Raj Bhatia Apr 04 '17 at 04:12

1 Answers1

1

Try with this:

(?i)lt[\s]*[\d]+

you can test it here

explanation:

  • flag (?i) tells regex that the search is case-(in)sensitive
  • lt - present literally
  • [\s]*space which can occur 0 or more times
  • [\d]+ digit which can occur 1 or more times,
Nino
  • 6,931
  • 2
  • 27
  • 42
  • Thank you so much Nino, It worked perfectly. I don't understand why these Regex are so scaring. – Raj Bhatia Apr 04 '17 at 04:49
  • @RajBhatia It's worth learning them. I'm suggesting you to try [this interactive tutorial](https://regexone.com/) (you can complete it in an hour if you're in a hurry) and then try to use that knowledge by reading here on SO or by spending some time on [regex crossword](https://regexcrossword.com/) – Nino Apr 04 '17 at 07:00
  • In case I need at least one space in front of "lt" if there is any text before "lt" then what I need to use, because its also changing aslt123 to ASLt123 where expected in this case is ASLT123 ..? – Raj Bhatia Apr 04 '17 at 12:36
  • @RajBhatia sorry, I don't understand. You need to check for one space before LT? – Nino Apr 05 '17 at 06:19