'Regex - Search VSCode files for one string following another (multiline) but where another string doesn't appear between them at the start of a line
In VSCode, I'm looking for all files that contain a return
statement followed by the word use
but that don't have const [A-Z]
at the start of a line in between them.
I'm using the search feature on the left-hand side of the editor.
The quantifier should be lazy.
For example, this should match the regex:
const Sample = (props: {data: string}) => {
if (!props.data) {
return null;
}
const Flex = styled.div`
display: flex;
`;
const [state, setState] = useState("example");
return <Flex>{props.data}</Flex>;
}
But this should not:
const Example1 = () => {
return null;
}
const Example2 = (props: {data: ReactNode}) => {
const [state, setState] = useState(null);
return props.data;
}
I have very little experience with regex so all I have currently is this: return(.|\n)+?use
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|