regex - Single repetition for some of the symbols in a set of characters -


i need regular expression matches string containing letters , symbols: @, . or space. symbols must appear once in whole string.

  • ^[@][.][a-z]+$ - matches example@.asdf need match 1 @ , 1 dot in string.

  • ^[a-z]+[@][a-z]+[.][a-z]+$ - best result now.

i wondering if can use - ^[a-z[@]{1}]$.

you realize away writing 6 permutations of 3 symbols. unfortunately, that's best can plain regular expressions because definition way regexp (seen finite state automata) can remember happened before through current state, can't have set store what's you've seen far.

so you'll have this. \a stands letters (you can expand [a-za-z]) because it's bad enough that. can use

\a*([@]?\a*[.]?\a*[ ]?|[@]?\a*[ ]?\a*[.]?|[.]?\a*[@]?\a*[ ]?|[.]?\a*[ ]?\a*[@]?|[ ]?\a*[.]\a*[@]|[.]?\a*[ ]\a*[@]|)\a* 

i threw in question marks after charactacters, each can appear "at most" once, if want once drop question marks.

evidently, if dealing 10 symbols , had write 10! permutations you'd better off writing function like

fun check_string_contains_symbols_once_at_most(str) {  c in str {   if symbol_list.contains(c) {    if symbol_seen_set.contains(c) return false    else if symbol_seen_set.add(c)   }  } } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -