简体   繁体   中英

Match the end of a SQL FROM clause with regex

I'm modifying a SQL view from some C# code. The view pulls data from a table that has a date at the end like so:

SELECT ...
FROM DAILY_TABLE_190801
WHERE ...

I'd like to pick out just the date part so that I can change it like this:

SELECT ...
FROM DAILY_TABLE_190802
WHERE ...

The only thing I could come up with was this expression with a lookbehind:

(?<=FROM.+)[0-9]{6}

but that does not work since regular expressions inside lookbehinds are not allowed.

Any ideas on how to achieve this?

I think this

^FROM (.+?(\d+))\s*$

should be enough, if SQL queries look like you posted. First group matches full table name, second (nested) matches decimal part of the name and \\s matches zero or more whitespace characters until end of line.

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