Jump to content

[SOLVED] help with substring


galayman

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ;) )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.