将状态名称转换为缩写的正则表达式 [英] regular expression to convert state names to abbreviations

查看:117
本文介绍了将状态名称转换为缩写的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目,该项目仅需要使用正则表达式将状态名称(必须区分大小写)转换为其两个字母的缩写。

I'm working on a project that requires only the use of regular expression to convert state names (must be case insensitive) to their two letter abbreviations.

I不能使用任何类型的开发环境或链接到任何数据库或xml或ini文件。

I cannot use any sort of development environment or link to any databases or xml or ini files.

请帮助!

推荐答案

由于状态中没有正则,因此正则表达式 WRONG 工具。我建议创建一个新项目。

Since states don't have something regular in them regular expressions is the WRONG tool. I would suggest getting a new project.

但是,唯一的解决方案(除了愚蠢的不合逻辑的骇客之外)是使每个状态都处于核心状态:

However, the only solution (apart from stupid illogical hacks) is to hardcore every state:

s/Alabama/Al/
s/Alaska/Ak/
...
s/Wyoming/Wy/

可以找到各州及其缩写的列表此处

A list of the states and their abbreviations can be found here.

这篇关于将状态名称转换为缩写的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆