java - check for a substring in a string before the first comma -


i have set of strings separated , example:

abc,defg,ijkl  pqrs,tu,vv  ,klmnop,qwe  aamn,nn,khhk 

as can see, third line doesn't start substring. starts comma.

using regex how can tell string starts substring of random length before first comma.

description

^"[^"]+", 

regular expression visualization

this regular expression following:

  • verifies string starts substring
  • requires substring random length greater zero

example

live demo

https://regex101.com/r/ke3bg5/1

sample text

abc,defg,ijkl pqrs,tu,vv ,klmnop,qwe aamn,nn,khhk 

sample matches

abc, pqrs, aamn, 

explanation

node                     explanation ----------------------------------------------------------------------   ^                        beginning of "line" ----------------------------------------------------------------------   [^,]+                    character except: ',' (1 or more times                            (matching amount possible)) ----------------------------------------------------------------------   ,                        ',' ---------------------------------------------------------------------- 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -