regex - Capturing a particular character from a string in Perl -


i have file contents this:

hfh_f_opl_j0                                       ;comment1 hij_i_aaa_v2_dsd                                   ;comment2 ale_h_fb_v1                                        ;comment3 zxzpoif_p                                              ;comment4 rst0drek_s                                              ;comment5 

i need match single character, present after first underscore, , 1 of [h, i, f, p, l, s] only.

what regex used this?

/(\w{3,})_([s|i|p|f|l|h]{1})(.*)\;/  

does not give right results.

use anchors , change first \w [a-z] because \w should match _. now, character want group index 1.

/^[a-z]{3,}_([sipflh]).*;/  

or

/^[^_]{3,}_\k[sipflh](?=.*;)/  

demo


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -