I
I
Isaac Clark2014-10-09 20:11:42
JavaScript
Isaac Clark, 2014-10-09 20:11:42

How to write a regular expression that will return a string?

Hello, tell me please.
There are lines that can be APPROXIMATELY of the following form:
['ss_SS'] ['tt_AA'] ['gg_A'] ['ff'] ['gg_AZZ']
The character inside the quotes can be any, this is just as an example.
The only thing they have in common is the square brackets and quotes inside the brackets.
Question: please tell me how to write 2 regular expressions that will return:
1st regular expression: characters before the underscore, that is, if there is a string ['ss_SS'] , then it should return 'ss' or if the string ['ss'], then 'ss' should return
2nd regular expression: all characters that are in quotes, that is, ['gg_AZZ'] - will return 'gg_AZZ'
I've been racking my brain all day...
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Zhak, 2014-10-09
@romanzhak

// если надо только скобки и кавычки убрать - необязательно использовать regexp
// \w эквивалентно [A-Za-z0-9_] 
"['gg_AZZ']".match(/\[\'(\w+)\'\]/)[1]; // gg_AZZ
"['gg_AZZ']".match(/[a-z]+/) // gg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question