I want to know how to match just the 1st character occurrence using regex
Output
# Address
cleanse.library.addressDoctor.AddressDoctor.UnlockCode:YR\\FKNT5ST3WCM:\\1J4JTCQQMH/H
cleanse.library.addressDoctor.AddressDoctor.DatabasePath:C:/AddressDoctor
cleanse.library.addressDoctor.AddressDoctor.Optimization:ADDRESSES_SORTED_BY_COUNTRIES
cleanse.library.addressDoctor.AddressDoctor.MemoryMB:600
cleanse.library.addressDoctor.AddressDoctor.CorrectionType:CORRECT_ONLY
cleanse.library.addressDoctor.AddressDoctor.PreLoad.CERTIFIED.PRELOAD_PART:US
cleanse.library.addressDoctor.AddressDoctor.PreLoad.CERTIFIED.PRELOAD_FULL:
cleanse.library.addressDoctor.AddressDoctor.PreLoad.CORRECTION_ONLY.PRELOAD_PART:CA, US
cleanse.library.addressDoctor.AddressDoctor.PreLoad.CORRECTION_ONLY.PRELOAD_FULL:
In this case I want to match just : (the 1st occurrence)
Update
Note: : (1st occurrence in every line)
You can test here
The pattern:
matches the start of the input (
^), followed by zero or more characters other than:([^:]*) followed by a:.So, this matches the first
:(and of course everything that precedes the:).So, let’s say you would like to replace the first
:with an@. You then simply group everything that precedes the first:, like this:and replace it with:
As shown here: http://regexr.com?2v8h8
EDIT
Most regex implementations do not allow a pattern to match the first
:in a line. You’d need a variable width look-behind assertion for such a thing, which simply is not supported by most languages.You could read the file line by line and split on the
:and provide a 2nd parameter that indicates the size of the array being returned:Many regex implementation have such a method (I can’t be more specific since I don’t know the language you’re using).