我正在研究验证法律描述中的季度数据的查询。我们的标准是输入像“SE/4”来标记东南角或“SE/4 NW/4”来标记西北角的东南角。我正在努力解决如何通过正则表达式来检查空格或字符串结尾的结构。
到目前为止,这是我的正则表达式的一些示例数据。
WITH test_data AS (
SELECT 'NW/4' AS quarter_cd FROM dual UNION ALL --VALID
SELECT 'E/2 SW/4' FROM dual UNION ALL --VALID
SELECT 'W/2' FROM dual UNION ALL --VALID
SELECT 'SW/4 NE/4' FROM dual UNION ALL --VALID
SELECT 'SW/4 NE/4 NW/4' FROM dual UNION ALL --VALID, THEY CAN REPEAT AN UNKNOWN NUMBER OF TIMES
SELECT 'E/2 N/2' FROM dual UNION ALL --TECHNICALLY VALID BUT WOULD LIKE TO EXCLUDE (1/2 of 1/2 is a 1/4) -> NE/4
SELECT 'E/2 SW/4, SE/4' FROM dual UNION ALL --INVALID, HAS A COMMA (TWO QUARTER ENTRIES ON ONE ROW)
SELECT 'E/2 SW/4 & SE/4' FROM dual UNION ALL --INVALID, HAS AN AMPERSAND (TWO QUARTER ENTRIES ON ONE ROW)
SELECT 'E/2 SW/' FROM dual UNION ALL --INVALID, INCOMPLETE ENTRY
SELECT 'SE/4SW/4' FROM dual UNION ALL --INVALID, NO SPACE BETWEEN DEFINITIONS
SELECT 'SE/2' FROM dual UNION ALL --INVALID, SOUTHEAST HALF DOES NOT MAKE SENSE
SELECT 'N/4' FROM dual UNION ALL --INVALID, NORTH QUARTER DOES NOT MAKE SENSE
SELECT 'LOT 1' FROM dual --INVALID, LOTS WILL BE DEALT WITH SEPARATELY
)
SELECT * FROM test_data
WHERE regexp_like(quarter_cd, '^([NSEW]/[2]{1}|[NSEW]{2}/[4]{1})+', 'c');
我的代码中的正则表达式只是我的众多尝试之一。我已经在查询中标记了应该返回的结果。为了简单起见,我愿意允许返回“E/2 N/2”,尽管从技术上讲它是无效的,因为北半部的东半部最好简化为东北部。上面的所有示例都是从我的数据中的实际条目中提取的。
任何帮助,将不胜感激。