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. Quote Link to comment 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... Quote Link to comment 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 = Quote Link to comment 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.