分解 R 中的长正则表达式 [英] breaking up a long regular expression in R

查看:36
本文介绍了分解 R 中的长正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我正在使用 R 和 stringr,我有一个很长的正则表达式,使用或"运算符,我将其保存到对象并与 stringr 一起使用.如何在 R 中将其分解为多行,这样我就不必在源代码编辑器中继续向右滚动?当我尝试使用逗号时,只能识别第一行.这个问题的大多数答案都是针对其他编程语言(即不是 R)的.

Problem: I am using R and stringr and I have a very long regular expression using the "or" operator that I save to an object and use with stringr. How can I break it up into multiple lines in R so I do not have to keep scrolling to the right in my source editor? When I try commas, only the first line is recognized. Most answers to this question have been for other programming languages (i.e. not R).

regex_of_sites <- "side|southeast|north|computer|engineer|first|south|pharm|left|southwest|level|second|thirteenth"

推荐答案

正则表达式只是一个字符串.您可以像任何其他字符串一样将其粘贴到多行中

The regular expression is just a string. You can paste it together across multiple lines like any other string

regex_of_sites <- paste0("side|southeast|north|computer|engineer|",
     "first|south|pharm|left|southwest|",
     "level|second|thirteenth")

这篇关于分解 R 中的长正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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