java - Regex for commas and periods allowed -


i tried searching answer question , reading regex wiki couldn't find i'm looking exactly.

i have program validates document. (it written else).

if lines or characters don't match regex error generated. i've noted few false errors generated , want correct this. believe have narrowed down problem this:

here example:

this error flagged program logic:

error: file header immediate origin name invalid: citibank, n.a.  

here code causes error:

if(strline.substring(63,86).matches("[a-z,a-z,0-9, ]+")){                                  }else{                                     joptionpane.showmessagedialog(null, "error: file header immediate origin name invalid: "+strline.substring(63,86));                                     errorfound=true;                                     fileheadererrorfound=true;                                     bw.write("error: file header immediate origin name invalid: "+strline.substring(63,86));                                     bw.newline(); 

i believe reason error called @ runtime because text contains period , comma.. unsure how allow these in regex.

i have tried using

if(strline.substring(63,86).matches("[a-z,a-z,0-9,,,. ]+")){ 

and seemed work wanted make sure correct way because doesn't right.

you're right in analysis, match failed because there dot in text isn't contained in character class.

however, can simplify regex - no need repeat commas, don't have special meaning inside class:

if(strline.substring(63,86).matches("[a-za-z0-9,. ]+")) 

are sure you'll never have match non-ascii letters or other kind of punctuation, though?


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -