Kshitij Yadav
Kshitij Yadav

Reputation: 1387

How can I ignore leading zero's in a RegEx capture?

I have a database which contains ID such as

        ID
000000000000000000000PBC_1164321
00000000000000000000000RP_395954
00000000000000000000000MOP_395954
00000000000000000000000395954

I want to get only the data after the leading 0's something like this:

ID
PBC_1164321
RP_395954
MOP_395954
395954

I am testing it on https://regexr.com. I tried using ^(0*) but it selects all the 0's. I want the opposite of it, not select all the leading 0 but everything after it. Kindly help.

I am not using any language such as Python and R. Just want to use regex to select/match anything apart from leading 0's

Upvotes: 2

Views: 1636

Answers (2)

Chthonyx
Chthonyx

Reputation: 707

Use /[A-Z1-9].*/gi [A-Z1-9] will match any character in A-Z 1-9 essentially not a 0, the dot matches any character and the star matches it 0 or more times. The tags match globally and case insensitive.

I initially attempted a solution similar to @Codelessbugging but was unable to get the site to process it correctly.

Link to this solution
Link to CodelessBugging solution

Upvotes: 1

codelessbugging
codelessbugging

Reputation: 2909

You can match text after the leading zeros using ([^0].*)

Upvotes: 2

Related Questions