编写让chatgpt识别的正则

1、编写prompt让ChatGPT写一个能识别首字母大写单词的正则

Status Code 200
JSON Response  {'id': 'chatcmpl-7lXqZITETrC90Jc4o7GvhSvWqYVM0', 'object': 'chat.completion', 'created': 1691565879, 'model': 'gpt-3.5-turbo-0613', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': 'The output of the code will be "G".'}, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 20, 'completion_tokens': 10, 'total_tokens': 30, 'pre_token_count': 4096, 'pre_total': 42, 'adjust_total': 41, 'final_total': 1}}
2、编写prompt让ChatGPT写一个能识别首字母大写且字符个数小于10的正则

Status Code 200
JSON Response  {'id': 'chatcmpl-7lZk25fMuAJqOnTJZOHYlQ2FeYLE1', 'object': 'chat.completion', 'created': 1691573162, 'model': 'gpt-3.5-turbo-0613', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': "The `re.search()` method takes two arguments - the pattern to search for and the string to search in. In this case, we are searching for a pattern that matches an uppercase letter followed by 0 to 9 word characters.\n\nThe code you provided will search the string `'Goodaxcerfvhjk'` for a match. Since the string starts with an uppercase letter `'G'`, it will return a match object.\n\nHere is an example:\n\n```python\nimport re\n\nstring = 'Goodaxcerfvhjk'\npattern = '[A-Z]\\w{0,9}'\n\nmatch = re.search(pattern, string)\nprint(match)\n```\n\nOutput:\n```\n<re.Match object; span=(0, 4), match='Good'>\n```\n\nThe result indicates that the match was found at positions 0 to 4 in the string. The matched substring is `'Good'`."}, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 26, 'completion_tokens': 183, 'total_tokens': 209, 'pre_token_count': 4096, 'pre_total': 42, 'adjust_total': 39, 'final_total': 3}}
3、编写prompt让ChatGPT写一个能识别单词末尾为标点符号的正则 

Status Code 200
JSON Response  {'id': 'chatcmpl-7la209nkEdyiLa2dV3Hq0XQokFi6b', 'object': 'chat.completion', 'created': 1691574276, 'model': 'gpt-3.5-turbo-0613', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': 'There seems to be a syntax error in the regular expression pattern you provided. The "\\w+" part represents one or more word characters, but the "\x08" characters preceding and following it are not valid syntax. If you remove these characters, the regular expression will work as expected. Here\'s the corrected version:\n\n```python\nimport re\nre.search(r\'\\w+(?=[,.!?])\', \'Goodaxcerfvhjk?\')\n```\n\nThis pattern will match any sequence of word characters that is followed immediately by a punctuation character (comma, period, exclamation mark, or question mark). So in the given example, it would match "Goodaxcerfvhjk" since it is followed by a question mark.'}, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 30, 'completion_tokens': 147, 'total_tokens': 177, 'pre_token_count': 4096, 'pre_total': 42, 'adjust_total': 40, 'final_total': 2}}
 

 

本文链接:https://my.lmcjl.com/post/14061.html

展开阅读全文

4 评论

留下您的评论.