mikesta707 Posted September 18, 2009 Share Posted September 18, 2009 Alright, so im trying to make 3 regex expressions. If i can figure out how to make this specific one work, than I can probably figure out the others. it has to match a line that looks like this Warrior john 100 every line must start with warrior, has to have a name composed of only alphabet characters, and a number. Note that the spacing must be exactly like shown, it cant have 2 or more spaces between each element. I currently have std::tr1::regex rgx1("^(Warrior) [a-zA-z]) [a-zA-z]) [0-9]{1,3}$)", std::tr1::regex_constants::icase);//warrior pattern this is in C++ i know, but it uses PCRE regex expressions so i expect that it will be similar if not that same. I always had a hard time with regex, so I just can't figure it out, but i expect its a pretty simple regex pattern. thanks in advance btw the std::tr1::regex_constants::icase part just makes the pattern case insensitive Quote Link to comment https://forums.phpfreaks.com/topic/174734-solved-basic-regex-expression-cant-figure-it-out/ Share on other sites More sharing options...
Garethp Posted September 18, 2009 Share Posted September 18, 2009 "^(Warrior ([a-zA-Z]+) ([0-9]{1,3})\s)+$" That should work Quote Link to comment https://forums.phpfreaks.com/topic/174734-solved-basic-regex-expression-cant-figure-it-out/#findComment-920869 Share on other sites More sharing options...
thebadbad Posted September 18, 2009 Share Posted September 18, 2009 ~^warrior [a-z]+ [0-9]{1,3}$~im The m modifier makes ^ and $ match at the start of the string and after a newline, and at the end of the string and before a newline, respectively. Quote Link to comment https://forums.phpfreaks.com/topic/174734-solved-basic-regex-expression-cant-figure-it-out/#findComment-920870 Share on other sites More sharing options...
mikesta707 Posted September 18, 2009 Author Share Posted September 18, 2009 excellent, thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/174734-solved-basic-regex-expression-cant-figure-it-out/#findComment-920892 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.