shortysbest Posted December 8, 2010 Share Posted December 8, 2010 I'm new to regexp, and i need help learning how to use it correctly. What would the equation look like if I wanted it to do this: If the string is: #!/profile&id=1 What would the expression be to return just "profile". Having it search after #!/ and &. The same for if I had a string like this: #!/profile&id=1&tab=home if i wanted to return just "profile" in one variable, and "tab" in another variable If you could sort of a explain the parts of the equation so I would know how to do it myself, that would be wonderful. Thanks. Link to comment https://forums.phpfreaks.com/topic/220986-help-with-javascript-regular-expressions-new-to-regexp/ Share on other sites More sharing options...
requinix Posted December 8, 2010 Share Posted December 8, 2010 http://www.regular-expressions.info/ /#!([^&]+)&id=\d+(&([^=]+)=home)/.match("#!/profile&id=1&tab=home") - /.../ is the expression - (...) gets captured for later - [^...] matches characters not included in the list - \d matches a digit - + means "one or more of the previous thing" I get the impression that the string can vary much more than as in the examples you gave... Link to comment https://forums.phpfreaks.com/topic/220986-help-with-javascript-regular-expressions-new-to-regexp/#findComment-1144266 Share on other sites More sharing options...
shortysbest Posted December 8, 2010 Author Share Posted December 8, 2010 Thanks, and yes, "profile" could be a number of things, same with tab, that could be a number of things, and there could also be more variables. #!/profile&id=1&tab=home&more_stuff=blahblah etc. What the expression would need to do is to select letters and numbers between #!/ and & and = Link to comment https://forums.phpfreaks.com/topic/220986-help-with-javascript-regular-expressions-new-to-regexp/#findComment-1144269 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.