简体   繁体   中英

Check that the "alpha" part of a string consists of only a certain sequence of characters - python

I am developing a listener to check if in a string representing a formula there are only vg digraphs such as "alpha" characters (a, b, c, etc..).

Eg:
vg/1000 * 2 Correct!
vl/1000 * 2 Wrong!

For now I have tried with regular expressions, using the following:
(.*vg.*)+ but I have the impression that it is not the best solution.


I'm thinking about the best way to write this check in python.
Any tips?
Thanks in advance!

If you want a regular expression that only accepts vg as a sequence of letters, then:

'^(\d*([\.\,]\d+)?[-+/*]?(vg)?)*$'

Otherwise if you want to choose from a set of letter sequences:

'^(\d*([\.\,]\d+)?[-+/*]?(vg|otherSequence)?)*$'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM