I've used regexp's for a while and have come to think I'm pretty good with them.
Though there was a problem I came across a while ago that I managed how to figure out another way that worked well. But I never was able to find an answer to the first way I tried to solve it. I just found this forum so I figured I'd ask here.
I wanted to be able to use this: [^_]* (where _ is any character)
with a string (where _ is a string) instead of just characters. I tried grouping and couldn't get it to work with a variety of different combinations of structures such as look ahead.
This is my goal:
[^(?:hi)]* so it continues until it reaches "hi" not just "h" or "i".
Maybe [^[[h]{1}{1}]{2}] ?
It would be nice to be able to use it for any string.
It's easy enough to search for a word, but to use a word as a deliminator I can't figure out.
using a string instead of a char to deliminate
Moderator: General Moderators
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Once you put characters into a character class, which is anything in brackets [], it is a selection of characters, not a sequence of characters. You can't nest character classes. It seems to me that you had a fundamental misunderstanding early on the learning process.
To select data up to a particular string, i.e. 'so it continues until it reaches "hi"':
Fairly simple.
To select data up to a particular string, i.e. 'so it continues until it reaches "hi"':
Code: Select all
(.*?)hiWhy not use a lookahead. This regex matches everything until 'hi' is reached.
Code: Select all
/.*(?=hi)/s