问题
I'm using the contact form 7 plugin for wordpress in combination with contact form db to display the field results in the front end. I'm trying to filter out the results in the shortcode, e.g.
<?php echo do_shortcode('[cfdb-value form="Testing" filter="FirstField~~/^s/"]'); ?>
This filter will only show values of FirstField that start with the letter s, is it possible to adapt this code to only show one word values (i.e. words with no spaces in). If this is at all possible? Any suggestions would be greatly appreciated!
回答1:
Here's a regex that won't non-words (including punctuation). It allows unicode though:
/^\w+$/u
DEMO
Pass:
correctfoobardefinitelynotunicodeæøå
No pass:
foo barbar-foofoo.barnoway, sir
回答2:
How about this one:
/^(\S+)/
This capture all characters that are not spaces from the beginning of the string.
回答3:
Try ^s[a-zA-Z0-9]\*$ Start with s and followed by any number of characters inside brackets []. Other way would be ^s[a-zA-Z0-9]\*\S$ which insists whitespace to be in the end of word! I did not test this code, but idea should be there.
来源:https://stackoverflow.com/questions/20701035/php-regex-modify-to-only-allow-one-word