简体   繁体   中英

How can I get wanted part from string with regular expression

I have a string like @'test' and I have to get only test word without @' '

how can I match them with regular expression at javascript?

try the regex below:

@\'([^']*)\'

get group(1)

and if your language supports look-behind,( eg python, perl, java...):

(?<=@\')[^']*

should work too without grouping.

oh, just saw you edit your question, as far as I know, js doesn't support look-behind, then you could take the option 1.

var firsName= "@'test'"

var objName = firsName .replace('@', "'"); lastName=objName.replace(/[']/g,'');

I fixed it like that. I dont know is it best way or not. thanks for helping

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM