galayman Posted November 29, 2007 Share Posted November 29, 2007 Hi All, 6 hours i'm trying to find this solution, but no luck. please can someone help me. I have this string (it's only some part of it, but the other line is the same) COMPOSITE 2671.895 AGRI 2539.764 i need to find this string first i'm using this regex [0-9] [A-Z] and this is the result : COMPOSITE 2671.895 AGRI 2539.764 is there any AND operator in regex? so first using this [0-9] [A-Z] and with AND operator to find [ ] so the result is : COMPOSITE 2671.895 AGRI 2539.764 or maybe there is another solution to find it? in short how to find this substring? COMPOSITE 2671.895 AGRI 2539.764 but there is two in the code, i only need to find the second one Thank you Best Regards Quote Link to comment Share on other sites More sharing options...
Orio Posted November 29, 2007 Share Posted November 29, 2007 You haven't said much... What can be changed in the string? I mean, does it always have these same numbers and letters? If that's the case, this will get your two : <?php $str = "COMPOSITE 2671.895 AGRI 2539.764"; preg_match("/(( ){2})A/", $str, $match); // $match[1] contains nbsp; (the second one) ?> Again, I am not sure exactly what you are trying to do here, why do you want to get two spaces anyway? Orio. Quote Link to comment Share on other sites More sharing options...
squiggerz Posted November 29, 2007 Share Posted November 29, 2007 maybe (COMPOSITE)+(.*?)([ ])+(.*?)([ ])+(.*?) match [5] being the second set? Are you just trying to get to the "AGRI" word? Quote Link to comment Share on other sites More sharing options...
galayman Posted November 29, 2007 Author Share Posted November 29, 2007 this is the full string : COMPOSITE 2671.895 AGRI 2539.764 MINING 3209.723 BASIC-IND 235.2 MISC-IND 442.814 CONSUMER 421.708 PROPERTY 227.708 INFRASTRUC 879.216 FINANCE 254.461 TRADE 385.862 MANUFACTUR 387.163 LQ 587.978 i need to find the second, fourth, sixth, eight, tenth and so on to replace it with br tag as you can see, i have bolded the can i find and replace it? what is the regex? This code : (( ){2})A/ will find COMPOSITE 2671.895 AGRI 2539.764 MINING 3209.723 BASIC-IND 235.2 MISC-IND 442.814 CONSUMER 421.708 PROPERTY 227.708 INFRASTRUC 879.216 FINANCE 254.461 TRADE 385.862 MANUFACTUR 387.163 LQ 587.978 and this code : (COMPOSITE)+(.*?)([ ])+(.*?)([ ])+(.*?) fill find COMPOSITE 2671.895 AGRI 2539.764 MINING 3209.723 BASIC-IND 235.2 MISC-IND 442.814 CONSUMER 421.708 PROPERTY 227.708 INFRASTRUC 879.216 FINANCE 254.461 TRADE 385.862 MANUFACTUR 387.163 LQ 587.978 but i need only the that located between the decimal and letter. Thank you, Best regards. Quote Link to comment Share on other sites More sharing options...
Orio Posted November 29, 2007 Share Posted November 29, 2007 See, now after you've explained everything nicely, it's easier to help you $str = preg_replace("/(\d+?) /", "$1|", $str); This will replace these spaces with a "|". Orio. Quote Link to comment Share on other sites More sharing options...
galayman Posted November 29, 2007 Author Share Posted November 29, 2007 Hi, i hope by keep asking this question i'm not make someone mad, thank you for your reply, but when i try to put this code : (\d+?) the result is this : COMPOSITE 2671.895 AGRI 2539.764 MINING 3209.723 BASIC-IND 235.2 MISC-IND 442.814 CONSUMER 421.708 PROPERTY 227.708 INFRASTRUC 879.216 FINANCE 254.461 TRADE 385.862 MANUFACTUR 387.163 LQ 587.978 Can you please help... i only need the Thank You, Best Regard Quote Link to comment Share on other sites More sharing options...
jcd Posted November 29, 2007 Share Posted November 29, 2007 Even though though the above match includes numerical digits, once you execute the preg_replace, the digits will not be replaced only the " " will. But if you really want just the " " to match you can do: (?<=\d) (I'm new to RegExps, sorry if my try gets you in more problems ) Quote Link to comment Share on other sites More sharing options...
galayman Posted November 29, 2007 Author Share Posted November 29, 2007 no is not, your solution works! thank you very much TOPIC SOLVED! 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.