A
A
Alexey Solodky2013-09-19 13:26:44
Regular Expressions
Alexey Solodky, 2013-09-19 13:26:44

Using a regular expression to get an array between two labels

#word1#--start--#word2#word3#dflsjdf#--end--#word4#word5#

Task: Use a regular expression to get an array of words between two marks (start, end) To get
word2, word3, dflsjdf
There can be any number of words.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Burov, 2013-09-19
@BuriK666

/--start--#(.*)#--end--/ and then split the result by # symbol

I
Ilya Yusupov, 2013-09-19
@x4fab

If only with one regular expression, then it can be like this:
/--start--#(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?(?:([^#]*)#)?--end--/
Only now an arbitrary number is no longer obtained, only up to a certain number (here - up to fifty). Well, the result will turn out, let's say, not quite clean - but here it all depends on the language used.

D
dikkini, 2013-09-19
@dikkini

(/--start--#(.*)#--end--/).split("#").toArray(); - one expression

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question