在java中使用正则表达式解析字符串(Parse a string using Regular Expression in java)
我试图使用正则表达式解析一个字符串。 我有一个内容文本:text我想解析一个包含text:text的字符串中的内容。 码:
String lines=" from:cal_date_d type:string relationship:many_to_one sql_on:${fact_customer.dw_update_date} = ${cal_date_d.dw_update_date}"; Pattern p = Pattern.compile("(\"?[\\w ]*)\\:(\"?([\\w]*)\"?)"); Matcher m = p.matcher(lines); while(m.find()) { String Column_Data=m.group(0); System.out.println("Regex: "+Column_Data); }
输出继电器:
from:cal_date_d type:string relationship:many_to_one sql_on:
预期产出:
from:cal_date_d type:string relationship:many_to_one sql_on:${fact_customer.dw_update_date} = ${cal_date_d.dw_update_date}
I am trying to parse a String using Regular expression. I have a content text:text and I want to parse the content from a string which has text:text. Code:
String lines=" from:cal_date_d type:string relationship:many_to_one sql_on:${fact_customer.dw_update_date} = ${cal_date_d.dw_update_date}"; Pattern p = Pattern.compile("(\"?[\\w ]*)\\:(\"?([\\w]*)\"?)"); Matcher m = p.matcher(lines); while(m.find()) { String Column_Data=m.group(0); System.out.println("Regex: "+Column_Data); }
Ouput:
from:cal_date_d type:string relationship:many_to_one sql_on:
Expected Output:
from:cal_date_d type:string relationship:many_to_one sql_on:${fact_customer.dw_update_date} = ${cal_date_d.dw_update_date}
原文:https://stackoverflow.com/questions/41499776
更新时间:2022-03-08 07:03
最满意答案
您可以将其转换为String并将其发送到服务器,您可以再次将其解码为jsonArray并获取值。
You can convert it to String and send it to server, where you can again decode it to jsonArray and get the values.
相关问答
更多-
有什么数据库专业书籍介绍?[2022-05-19]
mysql -
JQGrid,如何将JSON字符串发布到PHP来处理并发送到数据库?(JQGrid, How to post JSON string to PHP to Process and send to Database?)[2022-01-31]
只需删除多余的帖子defs。 //First decode the array $arr = $_POST["json"]; $decarr = json_decode($arr, true); $count = count($decarr); for ($x=0; $x < $count; $x++){ $newrec = $decarr; $id = $newrec['id']; $name = $newrec['name']; $id_continent = $newrec['id_cont ... -
您正在发送GET请求( $.getJSON ),但期望PHP中的POST变量: $catName = $_POST['catname']; 。 更改为$catName = $_GET['catname']; You are sending a GET request ($.getJSON) but expecting POST variables in your PHP: $catName = $_POST['catname'];. Change to $catName = $_GET['catname'] ...
-
如果将JSON放在帖子正文中,则无法从$ _POST获取数据。 看到这个问题用PHP接收JSON POST 。 php无法正确处理application/json 。 因为你的var_dump是空的,试试这个 var_dump(file_get_contents('php://input')); var_dump(json_decode(file_get_contents('php://input'), true)); 你会看到你的数据。 如果您发送数据而不将其更改为JSON,您将得到错误的数据。 例如: ...
-
您可以将其转换为String并将其发送到服务器,您可以再次将其解码为jsonArray并获取值。 You can convert it to String and send it to server, where you can again decode it to jsonArray and get the values.
-
HTTP请求可以是POST或GET但不是两者都有,并且您的代码试图通过$_POST和$_GET来访问变量,这是不行的。 我建议改用$_REQUEST ,它会照顾它(如果是POST或GET)。 尽管使用了type: "POST" ,但jQuery会将其视为“GET”请求,因为您指向带有查询字符串的URL。 HTTP request can be POST or GET but not both and your code is trying to access variables through $_POST ...
-
这里。 当使用mysql_query("INSERT...和if (!mysql_query($link))时,您正在调用mysql_query()两次,就像Andrewsi所说的那样 另外,你正在使用一个基于mysqli的方法mysql_real_escape_string($link摆脱了$link,或者更好的是,只使用mysqli_* 。 修改为$query = mysql_query("INSERT...然后使用查询变量” if (!$query,$link)代替。你可以做'{"structure":' + JSON.stringify(structure) + '}'或{structure: structure} 第一个是JSON字符串,因此jQuery不需要解析它。 第二个是javascript对象,所以jQuery确切知道如何解析它。 但是你混合了两者,所以jQuery很困惑并重新编码你的对象,因为你只编码了一半的对象。 所以另一种选择是JSON.stringify({structure: structure }) You can just do '{"stru ...我发现了这个问题。 正如我所说,我一个接一个地发问题,我为每个问题使用迭代,并发送给他们。 我的“JSONParser”对象不在迭代中。 它是在迭代类的开头,但不在迭代方法中。 因此,对于每次迭代,我的应用程序都会读取JSONParser对象的第一个实例。 在我移动这段代码之后JSONParser jsonParser = new JSONParser(); 在我的迭代方法中,我的问题解决了。 I have found the problem. As i said, i send questions one ...在评论部分,您似乎只希望将JSON发送到您的PHP脚本。 通常,您将POST发布到PHP,并将其解压缩: 然后是一个小客户端示例: public static void main(String[] args) { String json = " ...
相关文章
更多- Java正则表达式
- JAVA 正则表达式教程(超详细)三(续)
- JAVA 正则表达式教程(超详细)二(续)
- 揭开正则表达式的神秘面纱
- JAVA 正则表达式教程(超详细)一
- Java String类
- 怎么得到String数组?
- 快速了解正则表达式
- redis 字符串(String) SET 操作
- 正则表达式 - 语法
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)