java - RegEx capturing first (or only) group of 7 numbers max in a numeric/space string -


the exact rule (translate french, hope correct) :

6th rule : in case string numeric (eventually spaces) , first or series of numbers less or equal 7 character, serie our "title n°"

  • "1122584 44588985 1211" must return "1122584"
  • " xx 122585 12585" must not match
  • " 122585 1258xx5" must not match
  • " 12224457887 5896" must return "5896"
  • " 1458 125828 " must return "1458"

according me "the first or only" useless, if find 1 i'm ok, no matter if it's 1 'cause it's first. can't manage both checking if whole string numeric/space , finding group matching.

i'll use regex in java 7, library : https://docs.oracle.com/javase/7/docs/api/java/util/regex/pattern.html

edit :

^[0-9\s]*$ regex check numeric/space string

([0-9]{1,7}) captur group

i can't figure how combine 2 expressions.

([0-9]{1,7}) capture group, , want make sure other characters numeric/space.

so becomes ^[0-9\s]*?\b([0-9]{1,7})\b[0-9\s]*$


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -